2

I can compile the project and parse data well , but my Log Messages shows Error:com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON

and

Error:com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 186

I don't know why it was happened.

I try to find some answer , still can't find the way.

Here is my code that parse json data , i import import com.google.gson.JsonObject;:

@Override
    protected String doInBackground(String... params) {
        String url = params[0];
        String UD_MBID = params[1];
        String UD_TestCode = params[2];

        JsonObject jsonObject = new JsonObject();

        jsonObject.addProperty("UD_MBID", UD_MBID);
        jsonObject.addProperty("UD_TestCode", UD_TestCode);


        try {
            String routeJson = getRemoteData(url, jsonObject.toString());
            return routeJson;
        } catch (IOException ex) {
            Log.d(TAG, ex.toString());
            return null;
        }
    }

    private String getRemoteData(String url, String jsonOut) throws IOException {
        StringBuilder jsonIn = new StringBuilder();
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setUseCaches(false);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("charset", "UTF-8");
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
        bw.write(jsonOut);
        Log.d(TAG, "jsonOut" + jsonOut);
        bw.close();

        String line;
        int responseCode = connection.getResponseCode();
        if (responseCode == 200) {
            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            while ((line = br.readLine()) != null) {
                jsonIn.append(line);
            }
        } else {
            Log.d(TAG, "responseCode" + responseCode);
        }
        connection.disconnect();
        Log.d(TAG, "jsonIn" + jsonIn);

        return jsonIn.toString();

    }

Is anywhere can i set the setLenient(true) ?

Any ideas ? Thanks in advance.

Morton
  • 5,380
  • 18
  • 63
  • 118
  • Try this link : http://stackoverflow.com/questions/35984898/retrofit2-0-gets-malformedjsonexception-while-the-json-seems-correct – Rakshit Nawani Apr 05 '17 at 10:26
  • 1
    thanks for your information , but it says `Gson gson = new GsonBuilder()` , i don't use this code – Morton Apr 05 '17 at 10:30

0 Answers0