Iphone 如何创建下面给出的JSON数组字符串?
我想创建并发送下面给出的JSON数组字符串: 我使用的是JSON框架,它可以解析JSON数组,但是如何解析呢 创建JSON数组的步骤Iphone 如何创建下面给出的JSON数组字符串?,iphone,xcode,json,arrays,Iphone,Xcode,Json,Arrays,我想创建并发送下面给出的JSON数组字符串: 我使用的是JSON框架,它可以解析JSON数组,但是如何解析呢 创建JSON数组的步骤 { "deferred": [ { "API": "Test1", "data": "{\"uid\":\"16\",\"cid\":\"22\",\"watch\":\"12\"}", "timestamp": "12-01-2012 16:05:45" }, { "API": "Test
{
"deferred": [
{
"API": "Test1",
"data": "{\"uid\":\"16\",\"cid\":\"22\",\"watch\":\"12\"}",
"timestamp": "12-01-2012 16:05:45"
},
{
"API": "Test2",
"data": "{\"uid\":\"16\",\"cid\":\"22\"}",
"timestamp": "12-01-2012 16:05:45"
},
{
"API": "Test3",
"data": "{\"uid\":\"16\",\"cid\":\"22\",\"type\":\"n\"}",
"timestamp": "12-01-2012 16:05:45"
}
]
}
有什么建议吗?SBJSON同样有用。为了更好的指导 SBJSON将像
SBJSON *json = [[SBJSON new] autorelease];
NSMutableArray *ArrayResponse = [[NSMutableArray alloc] initWithArray:[json objectWithString:responseString error:nil]];
留下一个答案来总结这一切 正如我在评论中提到的,它是字典中数组中的字典 字典:
{
"API": "Test1",
"data": "{\"uid\":\"16\",\"cid\":\"22\",\"watch\":\"12\"}",
"timestamp": "12-01-2012 16:05:45"
},
{
"API": "Test2",
"data": "{\"uid\":\"16\",\"cid\":\"22\"}",
"timestamp": "12-01-2012 16:05:45"
},
{
"API": "Test3",
"data": "{\"uid\":\"16\",\"cid\":\"22\",\"type\":\"n\"}",
"timestamp": "12-01-2012 16:05:45"
}
可以这样创建:
NSDictionary *dict3 = [NSDictionary dictionaryWithObjectsAndKeys:@"Test3", @"API"
@"{\"uid\":\"16\",\"cid\":\"22\",\"type\":\"n\"}", @"data"
@"12-01-2012 16:05:45", @"timestamp"
, nil];
这些字典存储在一个数组中
NSArray *theArray = [NSArray arrayWithObjects: dict1, dict2, dict3, nil];
或者,您可以创建一个NSMutableArray,并在创建字典后立即在其中添加字典
该数组位于字典中:
NSDictionary *theBigDictionary = [NSDictionary dictionaryWithObject:theArray forKey:@"deferred"];
希望它能有所帮助:)首先,您需要在字典中进行json响应
然后传入数组它不是字典中数组中的字典吗?我可能错了,你是对的。考虑到你的解决方案,我解决了。@Dilip别忘了接受帮助你的答案-这就是StackOverflow的成长和帮助他人的方式。