I want to hardcode json in NSString variable. But I get errors. JSON is this:
{
"sub-categories": {
"parent": "1",
"count": "2",
"sub-category": [{
"id": "1",
"name": "Buy"
},
{
"id": "2",
"name": "Sell"
}]
}
}
I do this but it doesn’t work:
NSString *jsonArray = [NSString stringWithFormat:@"{
'sub-categories\": {
\"parent\": \"1\",
\"count\": \"2\",
\"sub-category\": [{
\"id\": \"1\",
\"name\": \"Buy\"
},
{
\"id\": \"2\",
\"name\": \"Sell\"
}]
}
}"];
In many languages a string literal cannot contain a new line. You can either write the whole JSON in 1 line, or split the string like this: