I have been trying to find encoding for below json strings from a day.
I am getting jSon string like
[
{
"ParentId": "154",
"TopMenuId": "159",
"MainMenuText": "开放时间",
"Language": "6",
"MenuImage": ""
},
{
"ParentId": "154",
"TopMenuId": "166",
"MainMenuText": "СЕРТИФИКАЦИЯ ISO",
"Language": "8",
"MenuImage": ""
}
]
with browser it looks ok. but when i get NSData String Encoding in NSLog it shows,
[
{
"ParentId": "154",
"TopMenuId": "159",
"MainMenuText": "开放时间",
"Language": "6",
"MenuImage": ""
},
{
"ParentId": "154",
"TopMenuId": "166",
"MainMenuText": "СЕРТИФИКАЦИЯ ISO",
"Language": "8",
"MenuImage": ""
}
]
I used almost all CFString Encoding but still do not get success.
Note: When i put NSLog in Browser it looks OK. but when it stores it in xcdatamodeld with string it store as С format.
please help me..
Thanks, in advance.
OK, there are two different kinds of encoding we’re talking about here. Any string is first and foremost encoded as byte sequence. I.e. the string “bits” is encoded as these bits in the ASCII encoding:
That’s the kind of encoding we’re talking about in code like:
But that’s not the problem you have. Your string is encoded in ASCII, but the characters in it are not represented as their actual characters, but as XML/HTML entities. I.e. instead of the letter
Сencoded in UTF-8, you have the HTML entityС, the byte encoding of which is pretty irrelevant.You need to either HTML-entity-decode those characters, or not HTML encode them to begin with before sending them. Having HTML entity representations of characters in a JSON string is pretty unusual and superfluous.