How to add backslashes to Json response in Java? -


i want used string getting server comes in json regular form. meant without \

  jsonparser parser=new jsonparser();    system.out.println("=======decode=======");    string s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";   object obj=parser.parse(s);   jsonarray array=(jsonarray)obj;   system.out.println("======the 2nd element of array======");   system.out.println(array.get(1));   system.out.println();    jsonobject obj2=(jsonobject)array.get(1);   system.out.println("======field \"1\"==========");   system.out.println(obj2.get("1"));         s="{}";   obj=parser.parse(s);   system.out.println(obj);    s="[5,]";   obj=parser.parse(s);   system.out.println(obj);    s="[5,,2]";   obj=parser.parse(s);   system.out.println(obj); 

in order send slashes in java, need escape them.

so assuming wanted receive {\"key\": \"value"\}, need escape each 1 of slashes, in addition escaping quotes: string s = "{\\\"key\\\": \\\"value\\\"}"; first 2 slashes in groups of 3 escape , produce slash. next slash escape quote, needed because of how java encloses strings in quotes.

now, that's how it, think it's worth considering if need it? json parser should able handle un-slashified responses.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -