本文整理汇总了Java中com.alibaba.fastjson.JSON.parse方法的典型用法代码示例。如果您正苦于以下问题:Java JSON.parse方法的具体用法?Java JSON.parse怎么用?Java JSON.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSON
的用法示例。
在下文中一共展示了JSON.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_point
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_point() throws Exception {
JSONSerializer serializer = new JSONSerializer();
Assert.assertEquals(AwtCodec.class, serializer.getObjectWriter(Point.class).getClass());
Point point = new Point(3, 4);
String text = JSON.toJSONString(point, SerializerFeature.WriteClassName);
System.out.println(text);
Object obj = JSON.parse(text);
Point point2 = (Point) obj;
Assert.assertEquals(point, point2);
Point point3 = (Point) JSON.parseObject(text, Point.class);
Assert.assertEquals(point, point3);
}
示例2: parseJSONObject
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
private static JSONObject parseJSONObject(String json){
Object obj = JSON.parse(json);
if (obj instanceof JSONObject) {
return (JSONObject) obj;
}
throw new IllegalArgumentException("The specified json string is not a JSON Object!");
}
示例3: test_error_1
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_error_1() throws Exception {
Exception error = null;
try {
JSON.parse("Se_[]");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例4: test_for_objectKey
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_objectKey() throws Exception {
User user = new User();
user.setId(1);
user.setName("leno.lix");
user.setIsBoy(true);
user.setBirthDay(new Date());
user.setGmtCreate(new java.sql.Date(new Date().getTime()));
user.setGmtModified(new java.sql.Timestamp(new Date().getTime()));
String userJSON = JSON.toJSONString(user, SerializerFeature.WriteClassName, SerializerFeature.WriteMapNullValue);
System.out.println(userJSON);
User returnUser = (User) JSON.parse(userJSON);
}
示例5: test_parserError
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_parserError() {
Exception error = null;
try {
String jsonString = "{PayStatus:0,RunEmpId:undefinedaa}";
JSON.parse(jsonString);
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例6: test_error_3
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_error_3() throws Exception {
Exception error = null;
try {
JSON.parse("Tree_et[]");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例7: test_1
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_1() throws Exception {
Map<Map<String, String>, String> map = new HashMap<Map<String, String>, String>();
Map<String, String> submap = new HashMap<String, String>();
submap.put("subkey", "subvalue");
map.put(submap, "value");
String jsonString = JSON.toJSONString(map, SerializerFeature.WriteClassName);
System.out.println(jsonString);
Object object = JSON.parse(jsonString);
System.out.println(object.toString());
}
示例8: test_for_objectKey
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_objectKey() throws Exception {
Map<Integer, User> map2 = new HashMap<Integer, User>();
User user = new User();
user.setId(1);
user.setIsBoy(true);
user.setName("leno.lix");
// user.setBirthDay(simpleDateFormat.parse("2012-03-07 22:38:21 CST"));
// user.setGmtCreate(new java.sql.Date(simpleDateFormat.parse("2012-02-03 22:38:21 CST")
// .getTime()));
map2.put(1, user);
String mapJson2 = JSON.toJSONString(map2, SerializerFeature.WriteClassName, SerializerFeature.WriteMapNullValue);
System.out.println(mapJson2);
Object object2 = JSON.parse(mapJson2);
}
示例9: test_for_issue
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
String text = "[[],{\"value\":[]}]";
Object root = JSON.parse(text, Feature.UseObjectArray);
Assert.assertEquals(Object[].class, root.getClass());
Object[] rootArray = (Object[]) root;
Assert.assertEquals(Object[].class, rootArray[0].getClass());
Assert.assertEquals(Object[].class, ((JSONObject)rootArray[1]).get("value").getClass());
}
示例10: test_error_7
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_error_7() throws Exception {
Exception error = null;
try {
JSON.parse("XreeSet[]");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例11: test_error_2
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_error_2() throws Exception {
Exception error = null;
try {
JSON.parse("Tre_Set[]");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例12: test_for_error
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_error() throws Exception {
Exception error = null;
try {
JSON.parse("new \"Date\"");
} catch (JSONException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
示例13: test_0
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_0 () throws Exception {
String text = "{\"errorMessage\":\"resource '/rpc/hello/none.json' is not found !\"}";
JSONObject json = (JSONObject) JSON.parse(text);
Assert.assertEquals("{\"errorMessage\":\"resource '/rpc/hello/none.json' is not found !\"}", json.toString());
}
示例14: test_for_issue
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
String text = "{\"amount\":1,\"channel_id\":\"wnys01\",\"gem\":1,\"id\":\"pay\",\"login_name\":\"U10722466A\",\"money\":1000,\"order_id\":\"99142AO10000086695A\",\"pay_channel\":\"weilan\",\"pay_time\":\"2015-11-05 20:59:04\",\"reward\":\"11:5_12:5_13:5,4:1_5:1_6:1\",\"status\":1,\"user_id\":19313}";
JSONObject obj = (JSONObject) JSON.parse(text);
Assert.assertEquals(1, obj.get("amount"));
}
示例15: toJSON
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public Object toJSON() {
return JSON.parse(JSON.toJSONString(this.elementsMap));
}