java json字符串转对象 用什么包 java怎么把字符串转换成jsonobject
java\u600e\u4e48\u5c06json\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3ajson\u5bf9\u8c61\u8f6c\u6362\u65b9\u6cd5\uff1a
import java.io.*;
import org.json.*;
public class Demo {
public static void main(String[] args) throws Exception {
String str = "{\"id_no\":\"342422198012001122\",\"mobile_no\":\"13666667789\",\"name\":\"\u5f90\u4e3d\"}";
JSONObject obj = new JSONObject(str); //\u5728\u8fd9\u91cc\u8f6c\u6362\u3002
System.out.println(obj);
System.out.println(obj.get("id_no")); // "342422198012001122"
}
}
\u8981\u5f15\u5165fast-json\u7684\u5305\u6216\u8005\u5f00\u6e90\u7684\u5305json.jar
\u8f6c\u6362\u65b9\u6cd5\uff1a
import java.io.*;
import org.json.*;
public class Demo {
public static void main(String[] args) throws Exception {
String str = "{\"id_no\":\"342422198012001122\",\"mobile_no\":\"13666667789\",\"name\":\"\u5f90\u4e3d\"}";
JSONObject obj = new JSONObject(str); //\u5728\u8fd9\u91cc\u8f6c\u6362\u3002
System.out.println(obj);
System.out.println(obj.get("id_no")); // "342422198012001122"
}
}
\u8981\u5f15\u5165fast-json\u7684\u5305\u6216\u8005\u5f00\u6e90\u7684\u5305json.jar
扩展阅读:java入门网站 ... java xml转json ... java list转json字符串 ... java中字符串转json ... javascript入门 ... java中json转换成对象 ... java replace ... js json字符串转对象 ... java python ...