如何从ios中的响应json字符串中找到键值?

时间:2014-08-21 05:41:48

标签: objective-c iphone json ios7

我正在使用AFNetworking获取json数据我使用此代码收到了这些数据......

 NSLog(@"Success: %@", [responseObject description]);
     NSDictionary *jsonDict = (NSDictionary *) responseObject;
     NSString *products = [jsonDict objectForKey:@"d"];
     NSLog(@"pro %@",products);

     NSString *newString = [NSString stringWithFormat:@"%@",products];
     NSData* data = [newString dataUsingEncoding:NSUTF8StringEncoding];

这里我们获得了成功的数据,这是产品的输出....

(
"{\"First\":\"TMT\",\"Second\":\"9a04f37d-8261-4898-94e7-0030b5aef3c1\"}",
"{\"First\":\"TRUS FOR PROSTATE\",\"Second\":\"4358a346-f69f-4e34-81ad-0657835eb69c\"}",
"{\"First\":\"TB PCR - Pus\",\"Second\":\"88370116-be77-4d9d-a170-08bd7ca1cc36\"}",
"{\"First\":\"TYPHIDOT IgG\",\"Second\":\"a14424a3-f1b1-4cde-9c8e-0bf214528fbf\"}",
"{\"First\":\"TB PCR - CSF\",\"Second\":\"ec2d08cd-d46c-48f9-b094-0c5789b47502\"}",
"{\"First\":\"TYPHIDOT (IgG \\u0026 IgM)\",\"Second\":\"592c4e58-7d03-49ab-a80e-0ca87dea8d14\"}",
"{\"First\":\"TLC,DLC\",\"Second\":\"fcbbde12-493a-4535-b895-0d5cb1db91e4\"}",
"{\"First\":\"TB PCR - BLOOD\",\"Second\":\"10288f38-45f5-433d-8d00-0deab0dbb08e\"}",
"{\"First\":\"TPHA\",\"Second\":\"d776f639-0eb7-4ab9-b72e-0e495915810c\"}",
"{\"First\":\"TOXOPLASMA IgG\",\"Second\":\"5975ecca-5f5a-4795-aadb-0fae3825b458\"}"
 ) 

但是现在我想从这个字符串中获取First的键值所以我使用下面的行但是我输出的jsonobjects是null。所以请告诉我如何获得关键价值。

     NSError* error;
     id jsonObjects = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
       NSLog(@"user id %@",jsonObjects);

0 个答案:

没有答案