我当前使用的没有 json 的代码是:
parts = [NSArray arrayWithObjects:
[[part alloc] initWithpartName:@"Part1" imageName:@"picture1.jpg"],
[part alloc] initWithpartName:@"Part2" imageName:@"picture2.jpg"],
[part alloc] initWithpartName:@"Part3" imageName:@"picture3.jpg"]
nil];
我获取的json是:
[{"id":"1","case_name":"NZXT Phantom
410","case_description":"","case_type":"ATX","case_color":"White","case_price":"99.99","case
_image":""},{"id":"2","case_name":"Thermaltake
MK+","case_description":"","case_type":"ATX","case_color":"Black","case_price":"84.99","case
_image":""}
我用它来获取它:
NSString *urlString = [NSString stringWithFormat:@"http://site.com/get/parts/part.php?part=case"];
NSURL *url = [NSURL URLWithString:urlString];
NSString *data = [NSData dataWithContentsOfURL:url];
问题:我怎么能把这个 json 放到这个数组中?我有 SBJson,我尝试使用它:
SBJsonParser *parser = [[SBJsonParser alloc] init];
parts = [[parser objectWithString:data error:nil] copy];
有人可以纠正我如何用颜色、描述、类型等额外数据解析它