Solved

Need help parsing JSON string in Java

Posted on 2014-11-03
1
117 Views
Last Modified: 2014-11-03
I'm learning to program Java using Android Studio Beta version 0.8.14.

I need to parse a JSON string into it's values.  The string is called "result" and it contains:

{"name":"JSON Example","version":"Simple Version"} 

Open in new window

Need simple code to turn that into two variables: strName and strVersion

Can you please provide code (and imports) to do that?

Thanks,
Jason
0
Comment
Question by:SqueezeOJ
1 Comment
 

Accepted Solution

by:
SqueezeOJ earned 0 total points
ID: 40420308
Think I answered my own question.  Code is:
JSONObject jObj = new JSONObject(result);
String strName = jObj.getString("name");
String strVersion = jObj.getString("version");
tvwOutput.setText(strName + ": " + strVersion);

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
replace a word with other 1 44
Oracle SQL syntax check  without executing 6 56
hibernate insert example 13 29
Crystal Reports Licensing Questions 4 12
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question