【发布时间】:2015-02-06 21:45:39
【问题描述】:
我正在尝试将文本字段数据从 json 存储到 NSDictionary。我为此使用了 SBJson。
{
"fields":[
{
"textFields":[
{
"text":"Congratulations",
"textSize":"12"
},
{
"text":"Best Wishes",
"textSize":"15"
},
{
"text":"Test text",
"textSize":"10"
}
]
},
{
"imageFields":[
{
"image":"test1.jpg",
"width":"200",
"height":"100"
},
{
"image":"test2.jpg",
"width":"200",
"height":"100"
}
]
}
]
}
我的代码:
-(void)readJson{
NSDictionary *jsonDict = [jsonString JSONValue];
NSDictionary *fieldsDict =[jsonDict valueForKey:@"fields"];
NSDictionary *textFieldsDict = [fieldsDict valueForKey:@"textFields"];
NSLog(@" Dictionary %@ ",textFieldsDict );
}
但它的输出如下。
Dictionary (
(
{
text = Congratulations;
textSize = 12;
},
{
text = "Best Wishes";
textSize = 15;
},
{
text = "Test text";
textSize = 10;
}
),
"<null>"
)
字典中似乎有两项,一项为空。我想将三个文本字段项放入数组中。我该如何解决这个问题。
【问题讨论】:
-
SBJson有效率问题。尝试使用iOS的NSJSONSerialization
标签: ios json nsdictionary sbjson