Java Code Examples for com.alibaba.fastjson.JSON.parse()

The following are Jave code examples for showing how to use parse() of the com.alibaba.fastjson.JSON class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: PointTest2.java   Source Code and License Vote up 6 votes
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);
}
 
Example 2
Project: bubichain-sdk-java   File: JSONBean.java   Source Code and License Vote up 5 votes
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!");
}
 
Example 3
Project: GitHub   File: JSONLexerTest_set.java   Source Code and License Vote up 5 votes
public void test_error_1() throws Exception {
    Exception error = null;
    try {
        JSON.parse("Se_[]");
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 4
Project: GitHub   File: Bug_for_lenolix_7.java   Source Code and License Vote up 5 votes
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);

}
 
Example 5
Project: GitHub   File: Bug_127_for_qiuyan81.java   Source Code and License Vote up 5 votes
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);
}
 
Example 6
Project: GitHub   File: JSONLexerTest_7.java   Source Code and License Vote up 5 votes
public void test_error_3() throws Exception {
    Exception error = null;
    try {
        JSON.parse("Tree_et[]");
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 7
Project: GitHub   File: Bug_for_NonStringKeyMap.java   Source Code and License Vote up 5 votes
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());
}
 
Example 8
Project: GitHub   File: Bug_for_lenolix_10.java   Source Code and License Vote up 5 votes
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);

}
 
Example 9
Project: GitHub   File: Bug_for_issue_423.java   Source Code and License Vote up 5 votes
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());
}
 
Example 10
Project: GitHub   File: JSONLexerTest_7.java   Source Code and License Vote up 5 votes
public void test_error_7() throws Exception {
    Exception error = null;
    try {
        JSON.parse("XreeSet[]");
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 11
Project: GitHub   File: JSONLexerTest_7.java   Source Code and License Vote up 5 votes
public void test_error_2() throws Exception {
    Exception error = null;
    try {
        JSON.parse("Tre_Set[]");
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 12
Project: GitHub   File: ParseErrorTest_12.java   Source Code and License Vote up 5 votes
public void test_for_error() throws Exception {
    Exception error = null;
    try {
        JSON.parse("new \"Date\"");   
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
 
Example 13
Project: GitHub   File: SlashTest.java   Source Code and License Vote up 4 votes
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());
}
 
Example 14
Project: GitHub   File: Bug_for_issue_446.java   Source Code and License Vote up 4 votes
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"));
}
 
Example 15
Project: webBee   File: Html.java   Source Code and License Vote up 4 votes
public Object toJSON() {
    return JSON.parse(JSON.toJSONString(this.elementsMap));
}
 
Example 16
Project: GitHub   File: Bug_7.java   Source Code and License Vote up 4 votes
public void test_doubleArray() throws Exception {
    double[] a = new double[] { 1, 2 };
    String text = JSON.toJSONString(a);
    JSON json = (JSON) JSON.parse(text);
    Assert.assertEquals("[1.0,2.0]", json.toJSONString());
}
 
Example 17
Project: GitHub   File: Bug_for_dubbo2.java   Source Code and License Vote up 4 votes
public void test_emptyHashMap() throws Exception {
	VO vo = new VO();
	vo.setValue(new HashMap());
	String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
	JSON.parse(text);
}
 
Example 18
Project: GitHub   File: Bug_7.java   Source Code and License Vote up 4 votes
public void test_floatArray() throws Exception {
    float[] a = new float[] { 1, 2 };
    String text = JSON.toJSONString(a);
    JSON json = (JSON) JSON.parse(text);
    Assert.assertEquals("[1.0,2.0]", json.toJSONString());
}
 
Example 19
Project: GitHub   File: Bug_127_for_qiuyan81.java   Source Code and License Vote up 4 votes
public void test_parserUndefined_b() {
    String jsonString = "{PayStatus:0,RunEmpId:undefined\b}";
    Object json = JSON.parse(jsonString);
    Assert.assertEquals("{\"PayStatus\":0}", json.toString());
}
 
Example 20
Project: GitHub   File: MapTest.java   Source Code and License Vote up 3 votes
public void test_map_2() throws Exception {
    VO vo = new VO();
    vo.setValue(new TreeMap<String, Object>());
    vo.getValue().put("1", "AA");
    
    String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
    
    System.out.println(text);
    
    VO vo2 = (VO) JSON.parse(text);
    
    Assert.assertEquals(vo.getValue(), vo2.getValue());
}