0

I have a json string like this:

String result={[{"id":"2","fullname":"Course 1"},{"id":"3","fullname":"Course 2"}]}

In java I wrote this code to decode that json string:

public class Courses {
public String id,name;  
}
Gson gs = new Gson();
Type listType = new TypeToken<List<Courses>>(){}.getType();
List<Courses> listCourses= gs.fromJson(result, listType);

But I always receive error:

06-09 04:21:11.614: E/AndroidRuntime(449): Caused by: java.lang.IllegalStateException: This is not a JSON Array.

What am I wrong?

Thanks :)

2 Answers 2

1

your json is not valid one..please check with some jsonvalidator whether the json is in correct format. To check the json Format refer the link

JSONFormat

To get the string from json, refer the below link as

AndroidJson

Parsing Json

I think it may helpful to you..

Sign up to request clarification or add additional context in comments.

Comments

0

you json string Result is not valid.see here valid or not

and it should be

[ { "id": "2", "fullname": "Course 1" }, { "id": "3", "fullname": "Course 2" } ]

JSONArray jsonArray = new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) {

   JSONObject objJson = jsonArray.getJSONObject(i);
   int id = objJson.getInt("id");
   String fullName = objJson.getString("fullname");

}

Comments

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.