I have few items which are: mobile_name, mobile_model, mobile_size (all are type of NSString)
I have to send this data on server in following JSON format:
{
"Mobile":
[
{
"name": "iPod Touch",
"model": "Any Model",
"size": "10",
}
]
}
How to create this data in JSON Format?
My approach is below.
My question is that, Is this approach correct OR are there some APIs or something like that which are used to create JSON in desired format?
I have to send this data on server in following JSON format:
{
"Mobile":
[
{
"name": "iPod Touch",
"model": "Any Model",
"size": "10",
}
]
}
How to create this data in JSON Format?
My approach is below.
Code:
NSMutableString *myJSON= [NSMutableString stringWithString:@"{ \"Mobile\" : [ "];
[myJSON appendString: [NSString stringWithFormat: @"{ \"name\" : \"%@\", \"model" : \"%@\", \"size\" : \"%@\" }",
mobile_name, mobile_model, mobile_size]];
[myJSON appendString@" ]}"];
My question is that, Is this approach correct OR are there some APIs or something like that which are used to create JSON in desired format?