Tag: json framework

如何parsing与其关键string没有引号的JSON?

我想parsing从iOS的SBJSON框架中的以下url产生的json输出http://maps.google.com/maps?q=school&mrt=yp&sll=13.006389,80.2575&output=json while(1);{title:"school – Google Maps",url:"/maps?q=school\x26mrt=yp\x26sll=13.006389,80.2575\x26ie=UTF8\x26hq=school\x26hnear=",urlViewport:false,ei:"RCu3T4eeMqSiiAe7k-yZDQ",form:{selected:"q",q:{q:"school",mrt:"yp",what:"school",near:""},d:{saddr:"",daddr:"",dfaddr:""},geocode:""}, 我正在使用http://www.bodurov.com/JsonFormatter/在线阅读。 在ASIHttpRequest响应方法中我删除while(1); 从响应 NSString *responseString = [[request resonseString]substringFromIndex:9]; //to remove while(1) SBJSONParser * parser = [[SBJSONParser alloc]init]; NSDictionary *jsonDict = (NSDictionary*)[parser objectFromString:responseString]; NSLog(@"%@",jsonDict) // prints null // [responseString JSONValue] also reports error 我猜JSON键没有双引号引起的问题。 我们得到{ title: “hospital – Google Maps”,“urlViewport”:false}而不是{ “title”: “hospital – Google Maps”,“urlViewport”:false, 请帮我parsing一下从Google返回的这个复杂的JSON结构。

使用Asihttprequest和iPhone的Json框架parsingJSON数据

我一直在学习如何使用JSON框架和iOS的ASIHTTPRequestparsingJSON。 我已经通过社区教程testing了使用twitter feed以及定制feed。 一切进展顺利。 然后我想我会testing使用Microsoft Odata服务Northwind分贝。 你可以在这里查看json的结果: http://jsonviewer.stack.hu/#http://services.odata.org/Northwind/Northwind.svc/Products%281%29?$format=json 现在我正在努力研究如何parsing产品名称。 任何人都可以指向正确的方向吗? 在我的要求已完成,我有这样的 : – (void)requestFinished:(ASIHTTPRequest *)request { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *responseString = [request responseString]; NSDictionary *responseDict = [responseString JSONValue]; //find key in dictionary NSArray *keys = [responseDict allKeys]; NSString *productName = [responseDict valueForKey:@"ProductName"]; NSLog(@"%@",productName); } 在日志中我有空。 如果我将valueForKey更改为@"d" ,则获得整个有效内容,但是我只想要productName。 我使用的服务url是: http://servers.odata.org/Northwind/Northwind.svc/Products(1)?$format=json

JSONparsing错误

我为iOS使用SBJson框架(也称为json-framework)。 parsing某个JSON文件时,出现以下错误: -JSONValue失败。 错误是:未转义的控制字符[0x09] ' 我已经使用了这个框架很多次,我也parsing了一个非常类似的JSON文件(甚至更长)在同一个应用程序,它工作正常。 我试着扔了一堆NSLogs,一切似乎都很好。 有人可以指点我这个错误是什么意思,或者至less如何继续debugging这样的错误? 以下是显示错误的代码: – (void)downloadSchedule:(NSString *)jsonString { // Get JSON feed URL and instantiate a dictionary object with its content NSDictionary *topDic = [jsonString JSONValue]; NSLog(@"topDic count %d", [topDic count]); topDic显示的计数为0.错误在[jsonString JSONValue]行。 谢谢