Using http get request i did get this json string:
hello
[
{
"upid":"1",
"uptitle":"test",
"uptype":"test",
"upsize":"1234",
"upname":"test",
"upuid":"1",
"uplocation":"1",
"uptimestamp":"2013-04-11 09:25:40"
},
{
"upid":"17",
"uptitle":"test",
"uptype":"video/mov",
"upsize":"2232",
"upname":"testing",
"upuid":"1",
"uplocation":"",
"uptimestamp":"2013-04-12 11:47:20"
}
]
How i can get it output in format:
upid:1
uptitle:test
uptype:test
upsize:1234
upname:test
upuid:1
uplocation:1
uptimestamp:2013-04-11 09:25:40
upid:17
uptitle:test
uptype:video/mov
upsize:2232
upname:testing
upuid:1
uplocation:
uptimestamp:2013-04-12 11:47:20
Here is my code:
NSMutableURLRequest *GETrequest = [[NSMutableURLRequest alloc] init];
[GETrequest setURL:[NSURL URLWithString:@"http:someip/upload/?id=1&command=alluseruploads&uid=1"]];
[GETrequest setHTTPMethod:@"GET"];
[GETrequest setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
// And to send and receive an answer, use a NSURLResponse:
NSURLResponse *response;
NSData *GETReply = [NSURLConnection sendSynchronousRequest:GETrequest returningResponse:&response error:nil];
NSString *theReply = [[NSString alloc] initWithBytes:[GETReply bytes] length:[GETReply length] encoding: NSASCIIStringEncoding];
NSLog(@"Reply: %@", theReply);
// converting string to data
NSData *jsonData = [theReply dataUsingEncoding:NSUTF8StringEncoding];
//NSLog(@"dic = %@", jsonData);
NSError* error;
id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
NSLog(@"%@", jsonObject);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…