我很惊讶如何通过删除iOS编程中的第一个对象来枚举JSON,如下所示 发件人
[{"001": {"name":"test", "url":"test"},"002":{"name":"test1", "url":"test1"},"003":{"name":"test2", "url":"test2"}}]
以
[ {"name":"test", "url":"test"},{"name":"test1", "url":"test1"},{"name":"test2", "url":"test2"}]
请帮助推荐我或建议编码。 谢谢。
答案 0 :(得分:1)
试试这个,
NSArray *jsonArray = //parsedJsonArray
NSDictionary *values = [jsonArray objectAtIndex:0];
NSArray *valuesArray = [values allValues];
valuesArray
将包含格式数据
[ {"name":"test", "url":"test"},
{"name":"test1", "url":"test1"}, {"name":"test2", "url":"test2"}]
答案 1 :(得分:0)
您可以轻松地将json字符串转换为NSMutableArray:
NSError *error;
// Get a NSMutableArray from the json string
NSData *data = [yourJsonString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableArray *arrayResult = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
// Remove the first object
[arrayResult removeObject:[arrayResult firstObject]];
答案 2 :(得分:0)
jsonDataArray1=[[NSMutableArray alloc]initWithArray:[JSON objectForKey:@"001"]];
jsonDataArray2=[[NSMutableArray alloc]initWithArray:[JSON objectForKey:@"002"]];
jsonDataArray3=[[NSMutableArray alloc]initWithArray:[JSON objectForKey:@"003"]];
jsonDataArrayFinal=[[NSMutableArray alloc]initWithObjects:jsonDataArray1,jsonDataArray2,jsonDataArray3 nil];
initialize all above arrays in viedidload