本文整理汇总了Java中net.minidev.json.JSONValue.parseWithException方法的典型用法代码示例。如果您正苦于以下问题:Java JSONValue.parseWithException方法的具体用法?Java JSONValue.parseWithException怎么用?Java JSONValue.parseWithException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minidev.json.JSONValue
的用法示例。
在下文中一共展示了JSONValue.parseWithException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActiveUserInfo
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
private JSONObject getActiveUserInfo() throws ParseException {
if(this.getActiveAgent() instanceof UserAgent){
UserAgent me = (UserAgent) this.getActiveAgent();
JSONObject o;
if(me.getUserData() != null){
System.err.println(me.getUserData());
o = (JSONObject) JSONValue.parseWithException((String) me.getUserData());
} else {
o = new JSONObject();
if(getActiveNode().getAnonymous().getId() == getActiveAgent().getId()){
o.put("sub","anonymous");
} else {
String md5ide = new String(""+me.getId());
o.put("sub", md5ide);
}
}
return o;
} else {
return new JSONObject();
}
}
示例2: testBool
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public void testBool() throws Exception {
String s = "{\"key1\":\"v1\", \"key2\":{}, \"key3\":[]}";
JSONObject o = (JSONObject) JSONValue.parseWithException(s);
assertEquals(o.get("key1"), "v1");
assertEquals(((JSONObject) o.get("key2")).size(), 0);
assertEquals(((JSONArray) o.get("key3")).size(), 0);
}
示例3: test
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Test
public void test() throws ParseException {
JSONObject objectToClean = jsonToClean != null ? (JSONObject) JSONValue.parseWithException(jsonToClean) : null;
JSONObject expectedObject = expectedJson != null ? (JSONObject) JSONValue.parseWithException(expectedJson) : null;
JSONObject toRemove = elementsToRemove != null ? (JSONObject) JSONValue.parseWithException(elementsToRemove) : null;
ElementRemover er = new ElementRemover(toRemove);
er.remove(objectToClean);
assertEquals(expectedObject, objectToClean);
}
示例4: fromJson
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public static MapQuery fromJson(String data) throws IOException {
try {
Object value = JSONValue.parseWithException(data);
if (value instanceof Map) {
return new MapQuery((Map<Object, Object>) value);
} else {
throw new IOException("Provided JSON data is not an JSON object");
}
} catch (ParseException e) {
throw new IOException("Failed to JSON data", e);
}
}
示例5: test01Float
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public void test01Float() throws Exception {
String s = "[01.0]";
// strict
MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_LEADING_0);
// PERMISIVE
JSONValue.parseWithException(s);
}
示例6: test
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
JSONObject objectSource = jsonSource != null ? (JSONObject) JSONValue.parseWithException(jsonSource) : null;
PathReplicator copier = switchKeyToCopy();
JSONObject copied = copier.replicate(objectSource);
JSONObject expectedObj = expected != null ? (JSONObject) JSONValue.parseWithException((String) expected) : null;
assertEquals(expectedObj, copied);
}
示例7: test0Float
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public void test0Float() throws Exception {
String s = "[00.0]";
// strict
MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_LEADING_0);
// PERMISIVE
JSONValue.parseWithException(s);
}
示例8: test
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
@Test
public void test() throws ParseException
{
JSONObject objectToSearch = jsonToSearch != null ? (JSONObject) JSONValue.parseWithException(jsonToSearch) : null;
PathLocator locator = switchKeyToRemove();
List<String> found = locator.locate(objectToSearch);
assertEquals(Arrays.asList(expectedFound), found);
}
示例9: testCreateObjectNode
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
/**
* Tests the AnnotationService for adding new nodes (for objects)
*/
@Test
public void testCreateObjectNode()
{
//AnnotationsClass cl = new AnnotationsClass();
MiniClient c = new MiniClient();
c.setAddressPort(HTTP_ADDRESS, HTTP_PORT);
JSONObject o;
try
{
c.setLogin(Long.toString(testAgent.getId()), testPass);
//add a new object
ClientResponse result=c.sendRequest("POST", mainPath +"objects", "{\"collection\": \"" + objectCollection + "\", \"toolId\":\"TestCase\"}", "application/json", "*/*", new Pair[]{});
assertEquals(200, result.getHttpCode());
assertTrue(result.getResponse().trim().contains("id"));
System.out.println("Result of 'testCreateObjectNode': " + result.getResponse());
try{
o = (JSONObject) JSONValue.parseWithException(result.getResponse());
} catch (ParseException e1) {
throw new IllegalArgumentException("Data is not valid JSON!");
}
String id = (String) o.get(new String("id"));
//check if object exists -> should pass
//retrieve the object information
ClientResponse select=c.sendRequest("GET", mainPath +"objects/" + id + "?part=id", "");
assertEquals(200, select.getHttpCode());
assertTrue(select.getResponse().trim().contains(id));
System.out.println("Result of select in 'testCreateObjectNode': " + select.getResponse().trim());
//add same object -> should fail with corresponding message
/*ClientResponse insertAgain=c.sendRequest("POST", mainPath +"objects", "{\"collection\": \"" + objectCollection + "\", \"toolId\":\"TestCase\"}");
assertEquals(409, insertAgain.getHttpCode());
assertTrue(insertAgain.getResponse().trim().contains("already"));
System.out.println("Result of try insert again 'testCreateObjectNode': " + insertAgain.getResponse().trim());*/
//delete object
ClientResponse delete=c.sendRequest("DELETE", mainPath +"objects/" + id + "", "");
assertEquals(200, delete.getHttpCode());
assertTrue(delete.getResponse().trim().contains("deleted"));
System.out.println("Result of delete in 'testCreateObjectNode': " + delete.getResponse().trim());
//check if object exists -> should fail
ClientResponse selectAfterDelete=c.sendRequest("GET", mainPath +"objects/" + id + "?part=id", "");
assertEquals(404, selectAfterDelete.getHttpCode());
assertTrue(selectAfterDelete.getResponse().trim().contains("not"));
System.out.println("Result of select after delete in 'testCreateObjectNode': " + selectAfterDelete.getResponse().trim());
}
catch(Exception e)
{
e.printStackTrace();
fail ( "Exception: " + e );
}
}
示例10: testExcessiveComma1O
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public void testExcessiveComma1O() throws Exception {
String s = "{\"a\":1,,\"b\":1}";
MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_CHAR);
JSONValue.parseWithException(s);
}
示例11: test0O
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public void test0O() throws Exception {
String s = "{\"t\":0}";
JSONObject o = (JSONObject) new JSONParser(JSONParser.MODE_RFC4627).parse(s);
assertEquals(o.get("t"), 0);
JSONValue.parseWithException(s);
}
示例12: testInt
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public void testInt() throws Exception {
String s = "123";
Object o = JSONValue.parseWithException(s);
assertEquals(o, 123);
}
示例13: testExcessiveComma1A
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public void testExcessiveComma1A() throws Exception {
String s = "[1,2,,3]";
MustThrows.testStrictInvalidJson(s, ParseException.ERROR_UNEXPECTED_CHAR);
JSONValue.parseWithException(s);
}
示例14: testFloat2
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public void testFloat2() throws Exception {
String s = "123.5E1";
Object o = JSONValue.parseWithException(s);
assertEquals(o, new Double(1235));
}
示例15: test0A
import net.minidev.json.JSONValue; //导入方法依赖的package包/类
public void test0A() throws Exception {
String s = "[0]";
JSONArray o = (JSONArray) new JSONParser(JSONParser.MODE_RFC4627).parse(s);
assertEquals(o.get(0), 0);
JSONValue.parseWithException(s);
}