?
Solved

Need help parsing JSON string in Java

Posted on 2014-11-03
1
Medium Priority
?
124 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
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 …
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.
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

764 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