我正在尝试从此 url 中提取数据,但遇到了一些问题。为什么会在上NSJSONSerialization
线时崩溃?有没有更好的方法从这个网站下载信息?
编辑:我将 jsonArray 从 NSArray 更改为 NSDictionary,但它仍然在同一个地方崩溃。有没有其他方法可以下载这些数据?
NSString *url=@"https://api.p04.simcity.com/simcity/rest/users/search/J3d1.json";
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSURLResponse *resp = nil;
NSError *err = nil;
NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &err];
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData: response options: NSJSONReadingMutableContainers error: &err];
NSLog(@"%@",jsonArray);
作为参考,JSON 是:
{
"users": [
{
"uri": "/rest/user/20624",
"tutorialState": 0,
"nucleusId": 20624,
"id": 20624,
"screenName": "R3DEYEJ3D1",
"lastLogin": 1362666027000,
"isOnline": "true",
"avatarImage": "https://api.p04.simcity.com/simcity/rest/user/20624/avatar",
"cities_count": 0,
"canChat": "true"
},
{
"uri": "/rest/user/46326",
"tutorialState": 0,
"nucleusId": 46326,
"id": 46326,
"screenName": "J3D1_WARR10R",
"lastLogin": 1363336534000,
"isOnline": "false",
"avatarImage": "https://api.p04.simcity.com/simcity/rest/user/46326/avatar",
"cities_count": 0,
"canChat": "true"
}
]
}