![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert a JSON String to Java Object using the json-simple library in Java?\n
The JSON is one of the widely used data-interchange formats and is a lightweight and language independent. The json.simple is a lightweight JSON processing library that can be used to encode or decode a JSON text.
In the below program, we can convert a JSON String to Java object using the json.simple library.
Example
import org.json.simple.*; import org.json.simple.parser.*; public class ConvertJSONStringToObjectTest { public static void main(String[] args) { String jsonString = "{\"Name\":\"Raja\",\"EmployeeId\":\"115\",\"Age\":\"30\"}"; JSONParser parser = new JSONParser(); JSONObject obj; try { obj = (JSONObject)parser.parse(jsonString); System.out.println(obj.get("Name")); System.out.println(obj.get("EmployeeId")); System.out.println(obj.get("Age")); } catch(ParseException e) { e.printStackTrace(); } } }
Output
Raja 115 30
Advertisements