【发布时间】:2011-06-29 15:08:20
【问题描述】:
JSON_CATEGORY_DATA_URL_STRING 是我的提要 URL,它返回如下:
[
{
"group":"For Sale",
"code":"SSSS"
},
{
"group":"For Sale",
"category":"Wanted",
"code":"SWNT"
}
]
我似乎无法从以下代码中得到一个不错的NSDictionary(或NSArray):
+ (NSDictionary *)downloadJSON
{
NSDictionary *json_string;
NSString *dataURL = [NSString stringWithFormat:@"%@", JSON_CATEGORY_DATA_URL_STRING];
NSLog(@"%@",dataURL);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:dataURL]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
json_string = [[[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]autorelease];
NSDictionary *json_dict = (NSDictionary *)json_string;
NSLog(@"json_dict\n%@",json_dict);
NSLog(@"json_string\n%@",json_string);
return json_string;
}
我已经阅读了很多关于此的帖子,但没有得到它。
【问题讨论】:
-
FWIW,JSONValue 只返回 null?
-
嗯......原来这是一个糟糕的提要。原始代码很好(甚至在重写 6 次并在此处发布之前)。
标签: ios objective-c nsarray nsdictionary sbjson