Recently in the project development, due to the background interface problems, there is a "\" such data, according to the general development of JSON data read, will not be recognized, because in the general language "\" are escaped, then the problem, how to solve it?
This problem has plagued me for a long time, first of all, let's look at the Bejson to identify the normal JSON data:
This is the normal JSON data, now add a "\" in the data and then look at:
The error! In fact, if you test with a carriage return, there will be surprises:
Did it fail too? This problem, I have a feeling of collapse, in addition to the use of third-party library, feel, the other will not love again, I think of the solution, usually, some rigid, the method is as follows:
I generally use the download third-party library afnetworking
//json parsing
//NSString *mustr=[[nsmutablestring alloc]
//initwithdata:responseobject encoding:nsutf8stringencoding];//binary converted to string
//mustr=[mustr stringbyreplacingoccurrencesofstring:@ "\ \" withstring:@ ""];//replace the contents of the string inside
//NSLog (@ "%@", mustr);//print a bit
///Responseobject=[nsmutabledata datawithdata:[mustr datausingencoding:nsutf8stringencoding]];//to convert the replaced string into binary, used to parse
This is a lazy (rotten) way, because there are a lot of terminal commands, there will be a backslash, so I personally think, in addition to the background need to do this aspect, that only self-parsing, or, directly skip this message, or,,, find a more mature third-party library is good,
Problems with "\" appearing in iOS development interface