在iPhone上提取JSON响应的特定部分
我正在考虑在我的应用程序中添加一个距离计算器。我一直在查看 Google 的 API,我似乎无法解码 JSON。我已经用 PHP 成功做到了这一点。其代码是:
substr($convertedtoarray['routes']['0']['legs']['0']['distance']['text'], 0, -3);
在 iPhone 上,我设法获取 JSON 响应,但无法获取我想要的特定部分。
Json 地址:http://maps.googleapis.com/maps/api/directions/json?origin=plymouth&destination=pl210bp&sensor=false
NSMutableDictionary *luckyNumbers = [responseString JSONValue];
[responseString release];
if (luckyNumbers != nil) {
NSString *responseStatus = [luckyNumbers objectForKey:@"routes"];'
}
我该去哪里?
任何帮助都会很棒。
I'm looking at adding a distance calculator to my application. I have been looking at Google's API put I can't seem to decode the JSON. I have managed to do so with PHP. The code for that was:
substr($convertedtoarray['routes']['0']['legs']['0']['distance']['text'], 0, -3);
On the iPhone I managed to get the JSON response but can't get the specific part of it that I want.
Json address: http://maps.googleapis.com/maps/api/directions/json?origin=plymouth&destination=pl210bp&sensor=false
NSMutableDictionary *luckyNumbers = [responseString JSONValue];
[responseString release];
if (luckyNumbers != nil) {
NSString *responseStatus = [luckyNumbers objectForKey:@"routes"];'
}
Where would I go from here?
Any help would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
非常丑陋,你可以像这样提取单独的对象:
祝你好运。
Very ugly you can extract in separate objects like this:
Good luck.
最简单的方法是创建一个字典迭代器,并循环遍历 luckynumbers 字典的子元素,您可以打印出来或调试,以查看这些子元素的键是什么,以及它们是什么对象类型。
我多次使用这种技术来弄清楚返回的 XML 文档的结构是什么样的。
The easiest thing to do would be to create a dictionary iterator, and loop over what children the luckynumbers dictionary has, you can print out, or debug, to see what the keys for these children are, and what object types they are.
I used this technique a few times to figure out what the structure of an XML doc I was being returned was like.