How to get different types of values from JSON object in Java?
A JSONObject is an unordered collection of key-value pairs and parses a text string to generate something like map object. A JSONObject has several important methods to display different types of values, such as the getString() method is used to get the string associated with the key string, getInt() method is used to get the integer value associated with the key, getDouble() method is used to get the double value associated with the key, getBoolean() method is used to get the double value associated with the key The associated boolean value.
Example
import org.json.*; public class JSONObjectTypeValuesTest { public static void main(String[] args) throws JSONException { JSONObject jsonObj = new JSONObject( "{" + "Name : Adithya," + "Age : 22, " + "Salary: 10000.00, " + "IsSelfEmployee: false " + "}" ); System.out.println(jsonObj.getString("Name")); // returns string System.out.println(jsonObj.getInt("Age")); // returns int System.out.println(jsonObj.getDouble("Salary")); // returns double System.out.println(jsonObj.getBoolean("IsSelfEmployee")); // returns true/false } }
Output
Adithya 22 10000.0 false
The above is the detailed content of How to get different types of values from JSON object in Java?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In the field of web development, XML and JSON, one of the data formats, are widely used, and the Gin framework is a lightweight Go language web framework that is simple, easy to use and has efficient performance. This article will introduce how to use the Gin framework to implement XML and JSON data parsing functions. Gin Framework Overview The Gin framework is a web framework based on the Go language, which can be used to build efficient and scalable web applications. The Gin framework is designed to be simple and easy to use. It provides a variety of middleware and plug-ins to make the development

Error handling in Golang: How to handle json parsing errors? In Golang, handling errors is a very important issue. Especially when dealing with external data, such as JSON data returned by network requests, we need to pay special attention to error handling. This article will introduce how to handle JSON parsing errors in Golang, and how to handle these errors gracefully. In Golang, JSON parsing errors are usually caused by incorrect data format or mismatched structure. when we look from the outside

Parsing JSON responses in Go: Use the Unmarshal function of the encoding/json package. Create a target structure that represents the JSON data. Read the HTTP response body and parse the JSON data. Print or use the parsed data.

With the development of the Internet era, data has become the basis of every form of information we are exposed to, and among them, JSON data format is often used in network data exchange. In order to facilitate the parsing and use of this data format, the Python language provides a JSON parsing library, which will be explained in detail in this article. 1. Introduction to JSON JSON (JavaScriptObjectNotation) is a lightweight data exchange format. Compared with XML, JSON is more concise and easier to

A JSONObject is an unordered collection of key-value pairs and parses a text string to produce a map-like object. A JSONObject has several important methods to display different types of values. For example, the getString() method is used to obtain the string associated with the key string, the getInt() method is used to obtain the integer value associated with the key, and the getDouble() method Used to get the double value associated with the key, the getBoolean() method is used to get the Boolean value associated with the key. Example importorg.json.*;publicclassJSONObjectTypeValuesTest{&

With the continuous development and application of Internet technology, front-end and back-end data interaction has become a necessary part of Web development. As a lightweight data exchange format, JSON has become one of the most popular choices. As an important language in the field of web development, PHP also provides a complete JSON processing function library, so developers can easily parse and generate JSON data. This article will introduce how to parse and generate JSON in PHP. 1. Basic concepts of JSON JSON (JavaScri

How to parse and generate JSON format in PHP In modern network development, JSON (JavaScriptObjectNotation) has become a commonly used data exchange format. It is lightweight, easy to read and write, and is widely used in various programming languages. PHP, as a popular server-side scripting language, also provides powerful support for parsing and generating JSON format data. This article will introduce how to parse and generate JSON format in PHP, including using

The Gson library can be used to parse JSON strings into tree models. We can use JsonParser to parse a JSON string into a tree model of type JsonElement. The getAsJsonObject() method of JsonElement can be used to obtain JsonObject and the getAsJsonArray() JsonElement method can be used to obtain elements in the form of JsonArray. Syntax publicJsonObjectgetAsJsonObject()publicJsonArraygetAsJsonArray()Example importjava.uti
