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


Java JSON.parse方法代码示例

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

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

}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:16,代码来源:AsyncRestServlet.java

示例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;
}
 
开发者ID:songsense,项目名称:Pregelix_Social_Graph,代码行数:16,代码来源:ProtocolOperation.java

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

示例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);
}
 
开发者ID:apache,项目名称:hbase,代码行数:5,代码来源:TestHttpServer.java


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