ios - Objective C 解析 JSON

标签 ios asp.net objective-c json wcf

我从我的 wcf 服务中获得了这个结果 JSON,我想在我的 ipad 应用程序中迭代它。我使用下面的代码来解析结果 json,但应用程序给出了错误。如何遍历此字典并获取项目。

iOS 代码:

   myArray = [NSMutableArray array];
        // Do any additional setup after loading the view.
        NSString* URL = @"http://www.unluapps.com/Service1.svc/ListTopReports";
        NSDictionary *dictionary = [JSONHelper loadJSONDataFromURL:URL ];
        NSString *result=[dictionary valueForKey:@"ListTopReportsResult"];
        NSLog(@"%@",result);

   /* for (NSString* key in result ) {

        id value=[result objectForKey:key];
        NSLog(@"%@ -+",value);

    }
   */

JSON:

{
ListTopReportsResult: [
{
AppUserID: null,
Author: "Joe Matthew",
Company: "Coca-Cola",
Country: "Poland",
CreationDate: "8/20/2014 4:32:00 AM",
EndDate: null,
ResearchReportID: "2",
Sector: "Soft Drinks",
Summary: "da ascon casmld lmasdlasd",
Title: "Can Coca-cola beat the market?",
URL: "2123123.pdf"
},
{
AppUserID: null,
Author: "martina pawlik",
Company: "Cimsa",
Country: "Poland",
CreationDate: "8/20/2014 4:31:00 AM",
EndDate: null,
ResearchReportID: "1",
Sector: "Cement",
Summary: "asd adas asd asdasd asdasdasd",
Title: "Poland's cement sector is on the rise",
URL: "1123123.pdf"
}
]
}

最佳答案

试试这个:

NSArray *result=[dictionary valueForKey:@"ListTopReportsResult"];

因为在您的 JSON 中,有一个用于键 ListTopReportsResult 的数组。

希望这对您有所帮助。 :)

关于ios - Objective C 解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25503943/

相关文章:

ios - 在 UIImage 周围绘制边框

iphone - 无法加载 UIWebView 中的 Facebook 评论

asp.net 用户控件部署

ios - PFObject 子类作为另一个 PFObject 子类中的属性

iphone - 类的 .h 文件中的 Typedef 枚举常量?

ios - 类型 "Int -> Bool","Int-> Bool -> Int","Int-> String -> Int-> Bool"

ios - SKShapeNode(路径: path) does not draw

javascript - 我如何在 asp.net mvc 中隐藏 div

asp.net - 如何在CommandItemTemplate中找到RadGrid的控件

ios - 如何获取 iOS 设备硬件规范?