Value of type java.lang.String cannot is converted to Jsonobject
The Jsonobject object throws this exception when parsing the JSON string returned by the server.
The JSON format that was supposed to be returned is wrong, and the comparison is hard to see why. At least the character of the format is no problem.
That could be the problem with coding. By carefully comparing each character, it is true that the character is found on the head of the JSON string: "\ufeff".
Client Solutions:
1 Public Static Finalstring Removebom (String data) {2 3 if(Textutils.isempty (data)) {4 5 returndata;6 }7 8 if(Data.startswith ("\ufeff")) {9 Ten returnData.substring (1); One A}Else { - - returndata; the - } -}
Server-Side solutions:
The output of this JSON PHP source is re-used editplus and the like with Utf-8 no BOM encoding saved. "Do not use the Windows system comes with Notepad to edit PHP source code, this BOM is notepad these Windows bring the editor introduced." 】
Another: When using Gson to parse the data, it is reported
java.lang.IllegalStateException error. This method can also be used to resolve.