Solved

Need help parsing JSON string in Java

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 59
How to convert from xls to xlsx using java 7 55
servlet and mdb, jms error 1 38
Is there a simpler dropbox system? 10 34
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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.

830 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