-1

I have a JSON string, how can I parse it and just get the valueString in java?

{
"resourceType": "Bundle",
"id": "0",
"entry": [
    {
        "resource": {
            "resourceType": "Basic",
            "extension": [
                {
                    "url": "http://ith.sahra.com/extensions#uploadid",
                    "valueString": "1589355494289_655"
                }
            ]
        }
    }
]

}

This is my code, I tried to call extension I got null but I got response while calling entry

 public static String ParsingValue(String valuepass) throws org.json.simple.parser.ParseException{
    Object obj = new JSONParser().parse(valuepass);
    JSONObject jo = (JSONObject) obj;
    //JSONArray msg = (JSONArray) jo.getClass();
    JSONArray result = (JSONArray) jo.get("entry");
}
ezra putra
  • 1
  • 1
  • 5

1 Answers1

0

The easiest way to parse a string through Jackson parser

Eg:

ObjectMapper mapper = new ObjectMapper();
String json = "{\"name\":\"anshul\",\"age\":29}";
Map<String, Object> map = mapper.readValue(json, Map.class);

Try this, it should solve your problem.

Anshul Sharma
  • 1,018
  • 3
  • 17
  • 39
  • thankyou so much, i already solved the problem with the reference of your code – ezra putra May 13 '20 at 23:25
  • One more point to note here is, if you have a POJO and JSON string is structured as per POJO you can directly parse it in a POJO. eg: ``` ObjectMapper mapper = new ObjectMapper(); String json = "{\"name\":\"anshul\",\"age\":29}"; User user = mapper.readValue(json, User.class); ``` – Anshul Sharma May 14 '20 at 01:10