How to parse received string into json in ios -
I also sends a message when applied to XMPP for its iOS app has received XML data and that from me Get the message Xml and make that string.
NSString * body = [[Message element FORM: @ "body"] stringValue];
Now * body json string and I'm parsing the string to json object using this line
NSData * data = [body DataUsingEncoding: NSUTF8StringEncoding]; // messageJSON NSDictionary message is JSON = [NSJSONSerialization JSONObjectWithData: Data Option: 0 Error: & amp; Error];
This is working well in normal text, but whenever someone sends a new line in the middle of the message, then it noses in solving my problem .. : - (
thanks in advance
output
{ "message": { "msg_type": "chat_success", "msg_content": { " Chat_id ":" 2 "," CHAT_MESSAGE ":" @ 34% *%%;% Fjfjfzz "," Sender_id ":" 24 "," Chat_det_taim ":" +1413538 99 8 "}}
error
error domain = NSCocoaErrorDomain code = 3840 "The operation can not be completed (cocoa error 3840.)" Character 94 AAS With UserInfo = 0x7fdf81c3a790 {NSDebugDescription = Unescaped control character.} (Character or omitted control character around 94)
I believe that the problem comes from the conversion of XML & lt; -> JSON.
in XML, Karejh returns and line feeds valid characters, ( & lt; P & gt;
and
). In JSON, Carriage Retire N / Line Feed \ n
(or system appropriate) Should be submitted by
Uje is not sure it will help, but none \ n
in your string before \\ n
it is serial.
Comments
Post a Comment