本文整理汇总了Java中org.eclipse.jetty.util.ajax.JSON.parse方法的典型用法代码示例。如果您正苦于以下问题:Java JSON.parse方法的具体用法?Java JSON.parse怎么用?Java JSON.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.util.ajax.JSON
的用法示例。
在下文中一共展示了JSON.parse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWriteJson
import org.eclipse.jetty.util.ajax.JSON; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testWriteJson() throws Exception {
StringWriter sw = new StringWriter();
ConfServlet.writeResponse(getTestConf(), sw, "json");
String json = sw.toString();
boolean foundSetting = false;
Set<String> programSet = new HashSet<>();
programSet.add("programatically");
programSet.add("programmatically");
Object parsed = JSON.parse(json);
Object[] properties = ((Map<String, Object[]>)parsed).get("properties");
for (Object o : properties) {
Map<String, Object> propertyInfo = (Map<String, Object>)o;
String key = (String)propertyInfo.get("key");
String val = (String)propertyInfo.get("value");
String resource = (String)propertyInfo.get("resource");
System.err.println("k: " + key + " v: " + val + " r: " + resource);
if (TEST_KEY.equals(key) && TEST_VAL.equals(val)
&& programSet.contains(resource)) {
foundSetting = true;
}
}
assertTrue(foundSetting);
}
示例2: onComplete
import org.eclipse.jetty.util.ajax.JSON; //导入方法依赖的package包/类
@Override
public void onComplete(Result result) {
// Extract results.
Map<String, Object> data = (Map<String, Object>) JSON.parse(utf8Content.toString());
if (data != null) {
Object[] results = (Object[]) data.get("results");
if (results != null) {
for (Object o : results) {
onLocationFound((Map<String, Object>) o);
}
}
}
doComplete();
}
示例3: getValue
import org.eclipse.jetty.util.ajax.JSON; //导入方法依赖的package包/类
private static String getValue(String fieldName) throws IOException {
String fieldValue;
String query = queryGenerator(fieldName);
query = queryNormalizer(query);
query = queryAPIGenerator(query);
fieldValue = Commander.sendGet(query);
HashMap<String,String[]> map = (HashMap<String,String[]>) JSON.parse(fieldValue);
Object[] path = map.get("results");
fieldValue = path[0].toString();
if (fieldValue.endsWith("\n")) {
fieldValue = fieldValue.substring(0, fieldValue.length()-1);
}
return fieldValue;
}
示例4: doGet
import org.eclipse.jetty.util.ajax.JSON; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (key == null) {
response.sendError(500, APPKEY + " not set");
return;
}
long start = System.nanoTime();
String loc = sanitize(request.getParameter(LOC_PARAM));
String lat = sanitize(request.getParameter(LATITUDE_PARAM));
String longitude = sanitize(request.getParameter(LONGITUDE_PARAM));
String radius = sanitize(request.getParameter(RADIUS_PARAM));
String[] keywords = sanitize(request.getParameter(ITEMS_PARAM)).split(",");
Queue<Map<String, Object>> results = new LinkedList<Map<String, Object>>();
// Make all requests serially.
for (String itemName : keywords) {
URL url = new URL(restQuery(lat + "," + longitude, radius, itemName));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader reader =
new BufferedReader(new InputStreamReader(connection.getInputStream()));
Map query =
(Map) JSON.parse(new BufferedReader(new InputStreamReader(connection.getInputStream())));
Object[] tmp = (Object[]) query.get("results");
if (tmp != null) {
for (Object o : tmp) {
Map map = (Map) o;
results.add(map);
}
}
}
// Generate the response.
String thumbs = generateResults(results);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head>");
out.println(STYLE);
out.println("</head><body><small>");
long now = System.nanoTime();
long total = now - start;
out.print(
"<b>Blocking: Requesting "
+ sanitize(request.getParameter(ITEMS_PARAM))
+ " near "
+ (loc != null ? loc : "lat=" + lat + " long=" + longitude)
+ "</b><br/>");
out.print("Total Time: " + ms(total) + "ms<br/>");
out.print("Thread held (<span class='red'>red</span>): " + ms(total) + "ms<br/>");
out.println(
"<img border='0px' src='asyncrest/red.png' "
+ "height='20px' "
+ "width='" + width(total) + "px'>");
out.println("<br/>");
out.print("First 5 results of " + results.size() + ":<br/>");
if ("".equals(thumbs)) {
out.print("<i>No results. Ensure " + APPKEY + " property is set correctly.</i>");
} else {
out.println(thumbs);
}
out.println("</small>");
out.println("</body></html>");
out.close();
}
示例5: parse
import org.eclipse.jetty.util.ajax.JSON; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static Map<String, Object> parse(String jsonString) {
return (Map<String, Object>)JSON.parse(jsonString);
}