1

I am trying to parse a json string of the format :

{"magha": {"2014-04-04 14:27:08.669217": "125"}}

I am not able to create a parser for the same. Looking forward for any help.

2
  • what have you implemented? Please show what have you tried. Commented Apr 4, 2014 at 9:26
  • String val={"magha": {"2014-04-04 14:27:08.669217": "125"}}; String val1=val.replaceAll("\"" , "\\\"");; JSONParser parser = new JSONParser(); ContainerFactory containerFactory = new ContainerFactory(){ public List creatArrayContainer() { return new LinkedList(); }public Map createObjectContainer() { return new LinkedHashMap(); }};try{ Map json = (Map)parser.parse(val1, containerFactory); Iterator iter = json.entrySet().iterator(); while(iter.hasNext()){ System.out.println(entry.getValue()); Commented Apr 4, 2014 at 10:08

1 Answer 1

3

Download the json-lib-jar

Use JSONObject

Do like this

JSONObject jobject=new JSONObject(yourjsonstring);
String magha=jobject.getString("magha");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help. Actually I am sending random values of string. So it is not appropriate to use a specific value. Is there any other way to parse the specified json string?

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.