我想从我的NSString中删除第一个和最后一个括号。
{
"Questions" : [
{
"title" : "This is my Question",
"question_id" : "123123123213",
"answers" : [
"correct answer 1",
"wrong answer 1",
"wrong answer 2",
"wrong answer 3"
],
"media_type" : "",
},
{
"title" : "This is my Question",
"question_id" : "2342342342342",
"answers" : [
"correct answer 1",
"wrong answer 1",
"wrong answer 2",
"wrong answer 3"
],
"media_type" : "",
}
]
}
我想从上面的{
中删除第一个和最后一个}
NSString
。
确保其不是Dictionary
。我在NSString
中有这个。
答案 0 :(得分:1)
<强>更新强>
该选项正在序列化:
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dictJson = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:nil];
NSArray *arr = dictJson[@"Questions"];
for (NSDictionary *dict in arr)
{
NSLog(@"title ==%@",dict[@"title"]);
.....
}
更新2
但要小心你的字符串。这是不对的。您必须在media_type:
之后检查逗号{
"Questions" : [
{
"title" : "This is my Question",
"question_id" : "123123123213",
"answers" : [
"correct answer 1",
"wrong answer 1",
"wrong answer 2",
"wrong answer 3"
],
"media_type" : ""**,** //THIS
},
{
"title" : "This is my Question",
"question_id" : "2342342342342",
"answers" : [
"correct answer 1",
"wrong answer 1",
"wrong answer 2",
"wrong answer 3"
],
"media_type" : ""**,** //AND THIS
}
]
}
没有逗号必须去那里。