Solved

Need help parsing JSON string in Java

Posted on 2014-11-03
1
114 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now