ios – 由foursquare为iPhone返回的解析json给出了无法识别的主角

ios – 由foursquare为iPhone返回的解析json给出了无法识别的主角,第1张

概述我正在尝试使用foursquare api来附近的地方. 这是从中返回的json数据 NSDictionary *results = [jsonString JSONValue]; NSLog(@"%@", results);( { code = 200; errorDetail = "This endpoint will stop return 我正在尝试使用foursquare API来附近的地方.
这是从中返回的Json数据

NSDictionary *results = [JsonString JsONValue]; NSLog(@"%@",results);(        {        code = 200;        errorDetail = "This endpoint will stop returning groups in the future. Please use a current version,see http://bit.ly/lZx3NU.";        errorType = deprecated;    },{        groups =         (                        {                items =                 (                                        {                        categorIEs =                         (                                                        {                                icon = "https://foursquare.com/img/categorIEs/parks_outdoors/default.png";                                ID = 4bf58dd8d48988d163941735;                                name = Park;                                parents =                                 (                                    "Great Outdoors"                                );                                pluralname = Parks;                                primary = 1;                                shortname = Park;                            }                        );

然后我尝试用数组获取组中的组列表

NSArray *groups = [ (NSDictionary *)results objectForKey:@"groups"];

这将返回以下错误

2011-11-05 11:42:12.907 XperIEnzApp[1972:207] No of results returned: 0 Results : (null)2011-11-05 11:42:13.225 XperIEnzApp[1972:207] -JsONValue Failed. Error trace is: (    "Error Domain=org.brautaset.JsON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x5849cd0 {NSLocalizedDescription=Unrecognised leading character}")2011-11-05 11:42:13.225 XperIEnzApp[1972:207] No of results returned: 0 Results : (null)

我该如何解析这个?

编辑:
我尝试了建议的技术,这给了我一个数组

ID groups = [[(NSDictionary *)results objectForKey:@"response"] objectForKey:@"groups"];    if ([results count] > 1){        NSLog(@"groups class %@\ngroups %@ %d",groups,[groups class],[groups count]);

日志输出的格式如下:

{                categorIEs =                 (                                        {                        icon = "https://foursquare.com/img/categorIEs/nightlife/danceparty.png";                        ID = 4bf58dd8d48988d11f941735;                        name = Nightclub;                        parents =                         (                            "Nightlife Spots"                        );                        pluralname = Nightclubs;                        primary = 1;                        shortname = Nightclub;                    }                );                contact =                 {                };                hereNow =                 {                    count = 0;                };                ID = 4eb33ba561af0dda8f673c1b;                location =                 {                    address = "144 Willow St 4R";                    city = brooklyn;                    crossstreet = PIErrepont;                    distance = 462;                    lat = "40.696864";                    lng = "-73.996409";                    postalCode = 11201;                    state = NY;                };                name = "Entertainment 720,Ltd.";                stats =                 {                    checkinsCount = 3;                    tipCount = 0;                    usersCount = 1;                };                verifIEd = 0;            }        );        name = Nearby;        type = nearby;    })groups __NSArrayM 1

这又不是Json而且难以解析,我如何在Json中获得输出.

解决方法 我是foursquare上的iPhone主角.我会试着去试试这里发生的事情.

首先,我强烈建议您使用JsONKit作为解析器.它重量轻,速度快:https://github.com/johnezang/JSONKit

您似乎正在正确解析JsON并正确获取字典.然后,您将记录解析的对象,而不是原始的JsON.您看到的输出是Objective-C如何选择将已解析的字典序列化为文本.绝对不是JsON.使用JsONKit,您可以将JsONString选择器发送到您的解析结果并将其转换回JsON并记录它.

如果您可以提供有关您要解决的问题的一些详细信息,我可以帮助您解决更多问题.正如Maudicus所说,请注意你要回来的错误.当我们对API进行更改时,您不希望应用程序中断.

总结

以上是内存溢出为你收集整理的ios – 由foursquare为iPhone返回的解析json给出了无法识别的主角全部内容,希望文章能够帮你解决ios – 由foursquare为iPhone返回的解析json给出了无法识别的主角所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1051336.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存