0

大家好,我是新的 iphone 开发人员。我从所需的 URL 获得响应,如下所示,我需要获取名称"CategoryID":1和名称"CategoryID":2都在单独的数组集中。如何实现在 iphone 中获取 JSON 对象的代码?感谢您获得响应的代码:

theXML = [[NSString alloc] initWithBytes: [RoutData mutableBytes] length:[RoutData length] encoding:NSUTF8StringEncoding];
NSLog(@"---->>>>>>-->>>:%@",theXML);

回复:

LocationTracking[1807:f803] ---->>>>>>-->>>:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getGearLockerCategoriesResponse xmlns="http://tempuri.org/"><getGearLockerCategoriesResult><status>SUCCESS</status><errorType /><errorMessage /><jsonString>[{"CategoryID":1,"ItemCount":1,"level":1,"Name":"Boots","Description":"Boots descrition","childs":[{"CategoryID":2,"ItemCount":1,"level":2,"Name":"Cold Water","Description":"Cold Water Description","childs":[]}]}]</jsonString><serverTimestamp>63477507673796</serverTimestamp></getGearLockerCategoriesResult></getGearLockerCategoriesResponse></soap:Body></soap:Envelope>

<jsonString>

[{"CategoryID":1,"ItemCount":1,"level":1,"Name":"Boots","Description":"Boots 

descrition","childs":[{"CategoryID":2,"ItemCount":1,"level":2,"Name":"Cold 

Water","Description":"Cold Water Description","childs":[]}]}]

</jsonString>

<serverTimestamp>63477390375625</serverTimestamp>

</DiveTravelerResponse> 
4

2 回答 2

0

Touch JSON 库是一个很好的解决方案:https ://github.com/TouchCode/TouchJSON

于 2012-07-09T06:18:16.100 回答
0

NSJSONSerialization. 如果您的 JSON 在名为“str”的 NSString 中:

NSError *jsonError = nil;
NSArray *rootObjectArray = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&jsonError];
if (rootObjectArray)
{
   /* you have a foundation object */
}
else
{
   /* something went wrong */
   NSLog(@"jsonError: %@", [jsonError localizedDescription]);
}
于 2012-07-09T06:21:16.923 回答