繁体   English   中英

从包含json数据的字符串中提取json数据

[英]extract json data from the string contains json data

我是java的新手,我的字符串包含:“ {'message':'hello'}”;

我想将上述字符串转换为提供“消息”键的JSON数据,将“ hello”作为值。 有人可以帮我吗?

我将使用json.org库 ,并执行以下操作:

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"));
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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