How do you get a specific value in json text in java?

Hello everyone,
How do I get a specific value in json text in java ?

Example -
Like json text is -

{
 "first" : "1st",
 "second" : "2nd"
}

So, how do I get the value for second ?

try a Google search next time
https://www.google.com/search?client=firefox-b-d&q=how+to+get+value+from+json+array+in+java
Taifun

You can use JSONObject

Wrong (ethically)!
This is the correct solution:

Ahh... Confused between array and object :laughing:

Still wrong.

Well Wait....

JSONObject jo = new JSONObject(JSON_STRING);
String second = jo.getString("second");

couldn't it can be done like this?

Yeah that's right.
However let him search somewhere before asking here for help.

1 Like

Thanks every1 for their reply. I'll test it and tell if I'm successful or not.
:grin:

You can also use built in block called "dictionary" for Parse JSON object

Yes, it is important to encourage people to use the tools to find the information they need. However, I don't think this was the most appropriate way to do it and @Techno_Vedang's response was valid.

4 Likes