当前位置: 首页>>代码示例>>Java>>正文


Java JSON.parse方法代码示例

本文整理汇总了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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:PointTest2.java

示例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!");
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:8,代码来源:JSONBean.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:JSONLexerTest_set.java

示例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);

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:Bug_for_lenolix_7.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:Bug_127_for_qiuyan81.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:JSONLexerTest_7.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:Bug_for_NonStringKeyMap.java

示例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);

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:Bug_for_lenolix_10.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:Bug_for_issue_423.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:JSONLexerTest_7.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:JSONLexerTest_7.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:ParseErrorTest_12.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:SlashTest.java

示例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"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:Bug_for_issue_446.java

示例15: toJSON

import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public Object toJSON() {
    return JSON.parse(JSON.toJSONString(this.elementsMap));
}
 
开发者ID:java-webbee,项目名称:webBee,代码行数:4,代码来源:Html.java


注:本文中的com.alibaba.fastjson.JSON.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。