0

I met a problem, but I don't know how to solve.Please help me, thank you! https://i.sstatic.net/Uu0me.png when:

new Gson().fromJson(server_response,Model.class);

Gson Error:

    Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 2621
2
  • Is my answer useful to you? Commented Jun 22, 2015 at 5:22
  • @ShoebSiddique hi.I was in for this problem. { "picurl": ["http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_0.jpg", "http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_1.jpg", "http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_2.jpg", "http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_3.jpg", "http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_4.jpg"] } ----Escape character?? Commented Jun 22, 2015 at 6:49

2 Answers 2

1

You can do something very simply like this.

try {
                    ArrayList<String> _pics = new ArrayList<String>();
                    JSONObject _jObject = new JSONObject("YOUR_JSON_STRING");
                    JSONArray _picArr  = _jObject.getJSONArray("picurl");
                    for (int i = 0; i < _picArr.length(); i++) {

                        String _picPath  = _picArr.getString(i);
                        _pics.add(_picPath);

                    }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
Sign up to request clarification or add additional context in comments.

Comments

0

Step 1: Convert your response into JSONObject

Step 2: Pass picurl JSONArray to Gson.

Type type = type = new TypeToken<List<Model>>() {}.getType();
Gson objGson = new Gson();
JSONObject response = new JSONObject(responseString);
List<Model> result = objGson.fromJson(response .getJSONArray("picurl").toString(), type);

2 Comments

.I judge because escape character ,what should I do?
{ "picurl": ["http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_0.jpg", "http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_1.jpg", "http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_2.jpg", "http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_3.jpg", "http:\/\/192.168.1.238:81\/upload\/postimg\/150510\/bc\/88177a488b_4.jpg"] } @Vicky Thakor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.