简体   繁体   中英

extract json data from the string contains json data

I am new to java my string contains : "{'message': 'hello'}";

I want to convert above string to JSON data that gives 'message' key gives 'hello' as value. can any one please help me out ?.

I would use the json.org library , and do something like this:

import org.json.JSONObject;

public class App 
{
    public static void main( String[] args )
    {
        String message = "{'message': 'hello'}";
        JSONObject json = new JSONObject(message);

        System.out.println(json.get("message"));
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM