0

How to convert %7B to { and %22 to " using Objective C and Xcode.

My jsonString is format is : %7B%22maxTemp%22:%2235%22

0yeoj
  • 4,500
  • 3
  • 23
  • 41

2 Answers2

0

It looks like you need to URL decode that string - perhaps the following post may be of use.

Community
  • 1
  • 1
Friedrich 'Fred' Clausen
  • 3,321
  • 8
  • 39
  • 70
0

I think there is something wrong with your NSJSONSerialization.

Here's a sample converting response data to JSONObject:

[NSJSONSerialization JSONObjectWithData:[YourResponseData]
                                options:NSJSONReadingAllowFragments
                                  error:&error];

Here's about your question, using stringByReplacingPercentEscapesUsingEncoding will do the trick:

NSString *string = [@"%7B%22maxTemp%22:%2235%22" stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

NSLog(@"%@", string);

From apples documentation:

Return Value A new string made by replacing in the receiver all percent escapes with the matching characters as determined by the given encoding encoding. Returns nil if the transformation is not possible, for example, the percent escapes give a byte sequence not legal in encoding.

Also, take note that this function is deprecated in iOS 9.0 you might want to read about that.


Output:

{"maxTemp":"35"
0yeoj
  • 4,500
  • 3
  • 23
  • 41