Search code examples
javajsonexceptiondecodejson-simple

Json String can't decode using json-simple toolkit java


JSON-Simple

JSON-Simple Example

String login = "{\"result\":[104192,42068],\"id\":1}";

Object obj = JSONValue.parse(login);

JSONArray array = (JSONArray)obj;

This throw a exception

Exception in thread "main" java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray

What is the problem in this code ?


Solution

  • In this case the parsed result is a JSONObject so you need to cast it to that.