首先要说,最好还是以key-value的字典形式和服务端交互最好,但是如果服务端要求以Array形式上传数据,那也是有解决办法的:
准备上传的数据:json格式
{
"key" :
[
{"type":"1","score":12},
{"type":"2","score":14},
{"type":"3","score":10}
]
}
使用SBJson
#import "SBJson.h"
SBJsonWriter *sbJson = [[SBJsonWriter alloc] init];
NSString *str = [sbJson stringWithObject:uploadArr];
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:str,@"key", nil];
输出结果
Printing description of str:
[{"type":"1","score":12},{"type":"2","score":14},{"type":"3","score":10}]
Printing description of dic:
{
scoreList = "[{\"type\":\"1\",\"score\":12},{\"type\":\"2\",\"score\":14},{\"type\":\"3\",\"score\":10}]";
}