Solved

Need help parsing JSON string in Java

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDFBox - convert image to PDF, PDF resolution 3 119
What is the latest versions eclipse neon 2 141
get weblogic logged in user in java 2 58
Java Server Faces parameter pass? 6 39
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

862 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

24 Experts available now in Live!

Get 1:1 Help Now