本文整理汇总了Java中net.minidev.json.parser.JSONParser类的典型用法代码示例。如果您正苦于以下问题:Java JSONParser类的具体用法?Java JSONParser怎么用?Java JSONParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSONParser类属于net.minidev.json.parser包,在下文中一共展示了JSONParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isJson
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
private static boolean isJson(Object o) {
if(o == null || !(o instanceof String)){
return false;
}
String str = o.toString().trim();
if (str.length() <= 1) {
return false;
}
char c0 = str.charAt(0);
char c1 = str.charAt(str.length() - 1);
if ((c0 == '[' && c1 == ']') || (c0 == '{' && c1 == '}')){
try {
new JSONParser(JSONParser.MODE_PERMISSIVE).parse(str);
return true;
} catch(Exception e){
return false;
}
}
return false;
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:21,代码来源:ValueNode.java
示例2: downloadLibraries
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
public static void downloadLibraries(String file) throws MalformedURLException, ParseException, IOException {
File launcherProfiles = new File(file + "download\\install_profile.json");
JSONParser p = new JSONParser();
JSONObject obj = (JSONObject) p.parse(launcherProfiles.toURL().openStream());
JSONObject versionInfo = (JSONObject) obj.get("versionInfo");
JSONArray libraries = (JSONArray) versionInfo.get("libraries");
for (Object lib2 : libraries) {
JSONObject lib = (JSONObject) lib2;
// if (lib.containsKey("clientreq")) {
// Boolean client = (Boolean) lib.get("clientreq");
// if (client) {
String name = (String) lib.get("name");
if (lib.containsKey("url")) {
CLUtil.downloadMaven(name, new File(file + "libraries\\"), (String) lib.get("url"));
} else {
CLUtil.downloadMaven(name, new File(file + "libraries\\"));
}
// }
// }
}
// System.exit(0);
}
开发者ID:mcNETDev,项目名称:CLauncher,代码行数:24,代码来源:CLUtil.java
示例3: add
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
@POST
public Response add(String in) {
JSONParser p = new JSONParser(JSONParser.MODE_RFC4627);
try {
JSONObject o = (JSONObject) p.parse(in);
UseCase uc = new UseCase();
uc.setTitle(o.getAsString("title"));
uc.setDescription(o.getAsString("description"));
uc.setScript(o.getAsString("script"));
uc.setModel(o.getAsString("model"));
uc.setHits(0);
uc.setLastHit(System.currentTimeMillis());
WriteResult<UseCase, String> result = getJacksonDBCollection().insert(uc);
String id = result.getSavedId();
return Response.ok(id).build();
} catch (Exception e) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
}
开发者ID:btrplace,项目名称:playd,代码行数:20,代码来源:Store.java
示例4: testBigDoubleInt
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
public void testBigDoubleInt() throws Exception {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; i++)
sb.append(Integer.MAX_VALUE);
sb.append('.');
for (int i = 0; i < 10; i++)
sb.append(Integer.MAX_VALUE);
String bigText = sb.toString();
BigDecimal big = new BigDecimal(bigText);
String s = "{\"t\":" + bigText + "}";
JSONObject o = (JSONObject) new JSONParser(JSONParser.MODE_RFC4627).parse(s);
assertEquals(o.get("t"), big);
o = (JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(s);
assertEquals(o.get("t"), big);
}
开发者ID:netplex,项目名称:json-smart-v1,代码行数:17,代码来源:TestInts.java
示例5: jsonFromString
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
/**
* Convert <code>jsonString</code> to a {@link JSONObject}
* @param jsonString
* @return
* @throws ServletException
*/
public JSONObject jsonFromString(String jsonString) throws ServletException {
//environment.logDebug("JSONFROMSTRING "+jsonString);
//NOTE: there are edge conditions:
// jsonString == "" can happen
JSONParser p = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
try {
return (JSONObject)p.parse(jsonString);
} catch (Exception e) {
environment.logError(jsonString, e);
throw new ServletException(e);
}
}
开发者ID:topicquests,项目名称:backside-servlet-ks,代码行数:19,代码来源:BaseHandler.java
示例6: jsonFromString
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
JSONObject jsonFromString(String jsonString) throws ServletException {
JSONParser p = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
try {
return (JSONObject)p.parse(jsonString);
} catch (Exception e) {
environment.logError("BadJSON: "+jsonString, e);
throw new ServletException(e);
}
}
开发者ID:topicquests,项目名称:backside-servlet-ks,代码行数:10,代码来源:UploadHelper.java
示例7: testParseRolesEndpoint
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
/**
* Verify the underlying JSONParser used by TokenUtils
* @throws Exception
*/
@Test(groups = TEST_GROUP_UTILS)
public void testParseRolesEndpoint() throws Exception {
JSONParser parser = new JSONParser(DEFAULT_PERMISSIVE_MODE);
InputStream contentIS = TokenUtils.class.getResourceAsStream("/Token1.json");
byte[] tmp = new byte[4096];
int length = contentIS.read(tmp);
byte[] content = new byte[length];
System.arraycopy(tmp, 0, content, 0, length);
JSONObject obj = (JSONObject) parser.parse(content);
System.out.println(obj);
}
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:17,代码来源:TokenUtilsTest.java
示例8: isJson
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
public static boolean isJson(String str) {
try {
JSONParser parser = new JSONParser();
Object obj = parser.parse(str);
if (obj instanceof JSONObject)
return true;
else
return false;
} catch (Exception e) {
return false;
}
}
开发者ID:ERS-HCL,项目名称:itest-starter,代码行数:13,代码来源:RestUtil.java
示例9: parseKeepingOrder
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
/**
* Parse Json input to a java Object keeping element order
*
* @since 1.0.6.1
*/
public static Object parseKeepingOrder(Reader in) {
try {
return new JSONParser(DEFAULT_PERMISSIVE_MODE).parse(in, FACTORY_ORDERED);
} catch (Exception e) {
return null;
}
}
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:13,代码来源:JSONValue.java
示例10: compress
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
/**
* Reformat Json input keeping element order
*
* @since 1.0.6.2
*/
public static String compress(String input, JSONStyle style) {
try {
StringBuilder sb = new StringBuilder();
ContentHandlerCompressor comp = new ContentHandlerCompressor(sb, style);
JSONParser p = new JSONParser(DEFAULT_PERMISSIVE_MODE);
p.parse(input, FACTORY_FAKE_COINTAINER, comp);
return sb.toString();
} catch (Exception e) {
return input;
}
}
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:17,代码来源:JSONValue.java
示例11: isValidJsonStrict
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
/**
* Check RFC4627 Json Syntax from input Reader
*
* @return if the input is valid
*/
public static boolean isValidJsonStrict(Reader in) throws IOException {
try {
new JSONParser(MODE_RFC4627).parse(in, FACTORY_FAKE_COINTAINER);
return true;
} catch (ParseException e) {
return false;
}
}
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:14,代码来源:JSONValue.java
示例12: isValidJson
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
/**
* Check Json Syntax from input Reader
*
* @return if the input is valid
*/
public static boolean isValidJson(Reader in) throws IOException {
try {
new JSONParser(DEFAULT_PERMISSIVE_MODE).parse(in, FACTORY_FAKE_COINTAINER);
return true;
} catch (ParseException e) {
return false;
}
}
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:14,代码来源:JSONValue.java
示例13: parse
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
public Object parse(Predicate.PredicateContext ctx){
try {
return parsed ? json : new JSONParser(JSONParser.MODE_PERMISSIVE).parse(json.toString());
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:8,代码来源:ValueNode.java
示例14: getControllerLeader
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
/**
* Returns the address of the currently active controller.
*/
public InetSocketAddress getControllerLeader() throws Exception {
String json = new String(zkClient.get().getData(
"/" + this.clusterName + "/CONTROLLER/LEADER",
false,
new Stat()));
// Parse this Json.
JSONObject object = (JSONObject)new JSONParser(
JSONParser.MODE_JSON_SIMPLE|JSONParser.ACCEPT_SIMPLE_QUOTE).parse(json);
String[] leaderHostPort = ((String)object.get("id")).split("_");
String host = leaderHostPort[0];
int port = Integer.parseInt(leaderHostPort[1]);
return new InetSocketAddress(host, port);
}
开发者ID:pinterest-attic,项目名称:terrapin,代码行数:17,代码来源:ZooKeeperManager.java
示例15: parseKeepingOrder
import net.minidev.json.parser.JSONParser; //导入依赖的package包/类
/**
* Parse Json input to a java Object keeping element order
*
* @since 1.0.9-2
*/
public static Object parseKeepingOrder(byte[] in) {
try {
return new JSONParser(DEFAULT_PERMISSIVE_MODE).parse(in, FACTORY_ORDERED);
} catch (Exception e) {
return null;
}
}
开发者ID:netplex,项目名称:json-smart-v1,代码行数:13,代码来源:JSONValue.java
注:本文中的net.minidev.json.parser.JSONParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论