In Android development, there is a coding problem when docking with the server-side interface, and the data obtained from the server is "\u8bbe\u59071id-\u8bbe\u59071\u540d\u79f0;\u8bbe\u59073id-\u8bbe\ The u59073\u540d\u79f0;\u8bbe\u59077id-\u8bbe\u59077\u540d\u79f0 "interface is returned by encoding the Json_encode in the PHP function. In the client through the Java.net.URLdecoder.decode () decoding is not used, but directly copy the above string to the decode () method can be normal decoding, the received string after Utf-8 code after the use, and finally search the relevant information on the Internet to find a solution.
One, Json_encode function:
json_encode-the variable with JSON encoding.
Description: String json_encode ($value) that returns the JSON form of value values.
Parameter: The value to be encoded, except for the resource type, can be any data type
The function can only accept UTF-8 encoded data (= character/string type of data)
Return value: The successful encoding returns a string in the form of JSON.
Second, the client decodes in the Java language:
The first of these methods
public string Unescapeunicode (String str) {
stringbuffer b=new stringbuffer ();
Matcher m = Pattern.compile ("\\\\u ([0-9a-fa-f]{4})"). Matcher (str);
while (M.find ())
B.append ((char) Integer.parseint (M.group (1));
return b.tostring ();
}
Just use the Unescapeunicode () method to decode it.
2. Using Json_simple.jar packet parsing
Download Address: http://www.jb51.net/softs/455885.html
Json.simple is a simple Java class library for parsing and generating JSON text. Does not depend on other class libraries, high performance.
Object Obj=jsonvalue.parse (JSONSTR); return obj.tostring ();
PHP Server-side workaround: