How to convert jsonString to JSONObject in Java

前端 未结 19 3040
一生所求
一生所求 2020-11-22 00:39

I have String variable called jsonString:

{\"phonetype\":\"N95\",\"cat\":\"WP\"}

Now I want to convert it into JSON Object. I

19条回答
  •  遥遥无期
    2020-11-22 01:21

    NOTE that GSON with deserializing an interface will result in exception like below.

    "java.lang.RuntimeException: Unable to invoke no-args constructor for interface XXX. Register an InstanceCreator with Gson for this type may fix this problem."
    

    While deserialize; GSON don't know which object has to be intantiated for that interface.

    This is resolved somehow here.

    However FlexJSON has this solution inherently. while serialize time it is adding class name as part of json like below.

    {
        "HTTPStatus": "OK",
        "class": "com.XXX.YYY.HTTPViewResponse",
        "code": null,
        "outputContext": {
            "class": "com.XXX.YYY.ZZZ.OutputSuccessContext",
            "eligible": true
        }
    }
    

    So JSON will be cumber some; but you don't need write InstanceCreator which is required in GSON.

提交回复
热议问题