Here is the simplified JSON file, I need to download it from a net service and parse results in a table!
EDIT: I provide now more precise code, cleaned and formatted by online tool:
{
"main": [
{
"id": 0, <--- float value
"type": "type0", <--- STRING value
"valueA": {
"valueA1": 1, <--- float value
"valueA2": 2, <--- float value
"valueA3": 3 <--- float value
},
"valueB": {
"valueB1": 1, <--- float value
"valueB2": 2 <--- float value
},
"valueC": [
{
"valueC1": "string0C1", <--- STRING value
"valueC2": 2, <--- float value
"valueC3": 3, <--- float value
}
]
},
FORMATTED by online tool jsonviewer.stack.hu:

I need to parse it with AFJSONRequestOperation, and I write this code:
NSMutableArray *main = [JSON objectForKey:@"main"];
arrayID = [main valueForKey:@"id"];
arrayType = [main valueForKey:@"type"];
NSMutableArray *arrayValueC = [main valueForKey:@"valueC"];
NSMutableString *stringC1 = [arrayValueC valueForKey:@"valueC1"];
// I CANT USE objectForKey, XCode give an exception -[__NSArrayI objectForKey:]: unrecognized selector sent to instance
NSLog(@"id: %@",arrayID);
NSLog(@"type: %@",arrayType);
NSLog(@"string: %@",stringC1);
When I parse, I get this results from NSLog:
id: (
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
)
type: (
type0,
type1,
type2,
type3,
type4,
type5,
type6,
type7,
type8,
type9
)
string: (
(
"string0C1"
),
(
"string2C1"
),
(
"string2C1"
),
(
"string3C1"
),
(
"string4C1"
),
(
"string5C1"
),
(
"string6C1"
),
(
"string7C1"
),
(
"string8C1"
),
(
"string9C1"
)
)
As u can see its all perfect, I can extrapolate every value of ID (float) and TYPE (string), but I hate the round brackets in every object of the valueC1 string: how can I get the clean valueC1 without brackets and quotation marks? Please if u can provide some code. Thanks!
Don’t use
valueForKey:. UseobjectForKey:instead. This is probably the major problem. But once you use it, you might run into new problem:The following contains a problem that will manifest itself when
arrayValueAis accessed the first time:The element stored at
valueAis an object i.e. a dictionary and not an array.Finally, your simplified JSON is invalid anyway. Several values are missing double quotes, e.g.:
should be:
You better shows the real JSON data and the real code.
Update:
You should be able to access the JSON data with the following code: