how to convert jsonobject

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

public class TestJSON {

	public static void main(String[] args) {

		JSONObject jObject = new JSONObject();

		jObject.put("EmployeeId", new Integer(121));
		jObject.put("Name", "Ramesh");
		jObject.put("Salary", new Double(15000.00));
		jObject.put("isPermanent", new Boolean(true));
		jObject.put("Nickname", null);
		
		//convert from JSONObject to JSON string
		String jsonText = jObject.toJSONString();

		System.out.println(jsonText);

		JSONParser parser = new JSONParser();
		
		//convert from JSON string to JSONObject
		JSONObject newJObject = null;
		try {
			newJObject = (JSONObject) parser.parse(jsonText);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		System.out.println(newJObject.get("EmployeeId"));
		System.out.println(newJObject.get("Name"));
		System.out.println(newJObject.get("Salary"));
		System.out.println(newJObject.get("isPermanent"));
		System.out.println(newJObject.get("Nickname"));
	}
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to convert a object to json string to json obhject json to obj converter org.json convert JSONObject to object jsonobject convert string to json convert classobject to json how to convert obj into json Java convert an object to jsonobject Java convert any object to jsonobject how to convert an object into json turn json string to bbject how ot convert object into json convert json to obj converter change json to object java cast object to jsonobject convert jsonvalue to jsonobject convert jsonobject to jsonobject how to convert object to jsonObject conver string to jsonObject how to convert org.json.JSONObject to json string how to convert json to object string json to jsonobject how to convert [object object] to json how to convert normal string to jsonObject how to convert string to jsonObject how to convert json to obj java convert JSONobject object to JsonObject convert miobject to json jsonobject to json converter json string to jsonobject cast jsonobject to java object how to convert from json to an object convert json to opject convert jsonobject to java object convert string to jsonobject create string to jsonobject Convert a JSON string to a custom object convert json to object angular how to convert json into object convert objects to json convert JSONObject to jsonbobject convert jsonbobject json convert object to jsonobject java convert string json to obect convert .obj to json convert java object to jsonobject how to convert object object to json JsonObject string to json convert jsonobject to string convert json string to jsonobject how to convert Set<string> to JsonObject convert an object to JSONObject string to JsonObject convert json to jobject Cannot cast from JSONObject to String how to convert jsonobject
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source