3

How can I create a basic JSON string? When I assign the the JSON value in NSString I get a semicolon error. How do I create this string without errors? Could you guys help me out? The code is below:

NSString *dam= @" {
    "Id": 23, "Ratings": {
    Picnicvanlig: 4, Barn Valning: 2, Badvanling: 5, etc..:3
}, "UserId": [email protected]
}";
3
  • 1
    Are you new to all of coding as well? Commented Feb 27, 2012 at 12:27
  • Glad to help. You do understand where the error came from? Objective-C (really, C in this case) thinks you're ending the string when it sees the second " character... you have to tell the compiler which double-quote characters are part of the string by 'escaping' them with a slash in front. Commented Feb 27, 2012 at 12:33
  • Duplicated, see stackoverflow.com/questions/6368867/… Commented Jan 29, 2013 at 17:19

1 Answer 1

5

Escape your quoted quotes:

NSString *dam= @"{\"Id\": 23, \"Ratings\": {\"Picnicvanlig\" : 4, \"Barn Valning\": 2, \"Badvanling\" : 5, \"etc..\" : 3 }, \"UserId\": \"[email protected]\"}";

Better yet, read Apple's JSON stuff.

Sign up to request clarification or add additional context in comments.

1 Comment

The string above is still not a JSON string. All of the keys have to be quoted and so does the email address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.