如何创建如下JSON字符串数组? [英] How to create JSON Array string given below?
本文介绍了如何创建如下JSON字符串数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要创建并发送JSON字符串数组如下:
我使用JSON框架,它可以解析JSON数组,但如何
创建JSON阵列
I want to create and to send JSON Array string given below: I am using JSON Framework, it can parse JSON array but how to create JSON Array
{
"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"
}
]
}
有什么建议?
推荐答案
留下一个答案来概括这一切。
Leaving an answer to summarize it all.
在我的评论中提到,它在字典中的数组的字典。
As I mentioned in a comment, it is a dictionary in an array in a dictionary.
字典:
{
"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];
这些词典存储在数组中。
These dictionaries are stored in an array.
NSArray *theArray = [NSArray arrayWithObjects: dict1, dict2, dict3, nil];
或者你可以做一个的NSMutableArray和创造他们之后有添加字典。
or you can make a NSMutableArray and add dictionaries there right after creating them.
和数组是一本字典:
NSDictionary *theBigDictionary = [NSDictionary dictionaryWithObject:theArray forKey:@"deferred"];
希望它能帮助:)
Hope it helps :)
这篇关于如何创建如下JSON字符串数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文