java.lang.String cannot be cast to org.json.simple.JSONObject simple-json

Roshan Wijesena

I am getting strange problem while trying to parse a simple json using simple-json by google.

Here is my code which is not working:

String s = args[0].toString();
JSONObject json = (JSONObject)new JSONParser().parse(s);

When I execute, it will give me the exception java.lang.String cannot be cast to org.json.simple.JSONObject

But when I hard code json directly like below its working fine. Wat could be the reason?

JSONObject json = (JSONObject)new JSONParser().parse("{\"application\":\"admin\",\"keytype\":\"PRODUCTION\",\"callbackUrl\":\"qwerewqr;ewqrwerq;qwerqwerq\",\"authorizedDomains\":\"ALL\",\"validityTime\":\"3600000\",\"retryAfterFailure\":true}");

UPDATE

When I print s, it will give me the output below:

"{\"application\":\"admin\",\"keytype\":\"PRODUCTION\",\"callbackUrl\":\"qwerewqr;ewqrwerq;qwerqwerq\",\"authorizedDomains\":\"ALL\",\"validityTime\":\"3600000\",\"retryAfterFailure\":true}"
Ankur Singhal

I ran this through eclipse by providing arguments in run configuration.

 public static void main(String[] args) {
        String s = args[0].toString();
        System.out.println("=>" + s);
        try {
            JSONObject json = (JSONObject) new JSONParser().parse(s);
            System.out.println(json);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

Output

=>{"application":"admin","keytype":"PRODUCTION","callbackUrl":"qwerewqr;ewqrwerq;qwerqwerq","authorizedDomains":"ALL","validityTime":"3600000","retryAfterFailure":true}


{"validityTime":"3600000","callbackUrl":"qwerewqr;ewqrwerq;qwerqwerq","application":"admin","retryAfterFailure":true,"authorizedDomains":"ALL","keytype":"PRODUCTION"}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject error when reading json file iwith java

From Dev

java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject

From Dev

"org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject"

From Dev

java.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to org.json.JSONObject while calling ParseCloud function

From Dev

parse.com java.lang.ClassCastException: java.util.HashMap cannot be cast to org.json.JSONObject

From Dev

org.json.JSONException: Value <div of type java.lang.String cannot be converted to JSONObject during the debugging

From Dev

org.json.JSONException: Value < of type java.lang.String cannot be converted to JSONObject

From Dev

error. org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

From Dev

org.json.JSONException: Value Data of type java.lang.String cannot be converted to JSONObject

From Dev

org.json.simple.JSONObject not found

From Dev

JSON Exception: java.lang.String cannot be converted to JSONObject

From Dev

java.lang.NoClassDefFoundError: org/json/JSONObject

From Dev

Error parsing data org.json.JSONException: Value <br><table of type java.lang.String cannot be converted to JSONObject

From Dev

ERROR: com.android.volley.ParseError: org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject

From Dev

org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject in Android Studio with phpserver

From Dev

String cannot be cast to org.json.JSONObject when login salesforce rest api

From Dev

How can I solve "org.json.simple.JSONObject cannot be resolved"?

From Dev

org.json.JSONObject cannot be cast to com.parse.ParseGeoPoint

From Dev

org.json.simple.jsonObject throws noclassdeffounderror proguard maven

From Dev

unable to access rest CXF with org.json.simple.JSONObject

From Dev

Encoding issue with org.json.simple.JSONObject - turning ★ to ★

From Dev

How to Fix java.lang.String org.json.JSONObject.toString()' on a null object reference?

From Dev

Get Org.json.JSONException:Value array(2) of type java.lang.String can not be converted to JSONObject

From Dev

Android JSON Parsing issue-java.lang.string cannot be converted to JSONObject

From Dev

Android JSON Parsing issue-java.lang.string cannot be converted to JSONObject

From Dev

Getting "java.lang.ClassNotFoundException: org.json.simple.parser.ParseException" while reading JSON object as input value of mapper

From Dev

Iterate through JSONObject from root in json simple

From Dev

org.json.JSONArray cannot be converted to JSONObject

From Dev

org.json.JSONObject cannot be converted to JSONArray

Related Related

  1. 1

    java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject error when reading json file iwith java

  2. 2

    java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject

  3. 3

    "org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject"

  4. 4

    java.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to org.json.JSONObject while calling ParseCloud function

  5. 5

    parse.com java.lang.ClassCastException: java.util.HashMap cannot be cast to org.json.JSONObject

  6. 6

    org.json.JSONException: Value <div of type java.lang.String cannot be converted to JSONObject during the debugging

  7. 7

    org.json.JSONException: Value < of type java.lang.String cannot be converted to JSONObject

  8. 8

    error. org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

  9. 9

    org.json.JSONException: Value Data of type java.lang.String cannot be converted to JSONObject

  10. 10

    org.json.simple.JSONObject not found

  11. 11

    JSON Exception: java.lang.String cannot be converted to JSONObject

  12. 12

    java.lang.NoClassDefFoundError: org/json/JSONObject

  13. 13

    Error parsing data org.json.JSONException: Value <br><table of type java.lang.String cannot be converted to JSONObject

  14. 14

    ERROR: com.android.volley.ParseError: org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject

  15. 15

    org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject in Android Studio with phpserver

  16. 16

    String cannot be cast to org.json.JSONObject when login salesforce rest api

  17. 17

    How can I solve "org.json.simple.JSONObject cannot be resolved"?

  18. 18

    org.json.JSONObject cannot be cast to com.parse.ParseGeoPoint

  19. 19

    org.json.simple.jsonObject throws noclassdeffounderror proguard maven

  20. 20

    unable to access rest CXF with org.json.simple.JSONObject

  21. 21

    Encoding issue with org.json.simple.JSONObject - turning ★ to ★

  22. 22

    How to Fix java.lang.String org.json.JSONObject.toString()' on a null object reference?

  23. 23

    Get Org.json.JSONException:Value array(2) of type java.lang.String can not be converted to JSONObject

  24. 24

    Android JSON Parsing issue-java.lang.string cannot be converted to JSONObject

  25. 25

    Android JSON Parsing issue-java.lang.string cannot be converted to JSONObject

  26. 26

    Getting "java.lang.ClassNotFoundException: org.json.simple.parser.ParseException" while reading JSON object as input value of mapper

  27. 27

    Iterate through JSONObject from root in json simple

  28. 28

    org.json.JSONArray cannot be converted to JSONObject

  29. 29

    org.json.JSONObject cannot be converted to JSONArray

HotTag

Archive