• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JSON类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.jetty.util.ajax.JSON的典型用法代码示例。如果您正苦于以下问题:Java JSON类的具体用法?Java JSON怎么用?Java JSON使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JSON类属于org.eclipse.jetty.util.ajax包,在下文中一共展示了JSON类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onExecute

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
@Override
public void onExecute(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, String[]> parameterMap = request.getParameterMap();
    ParamMap params = new ParamMap();

    for (Map.Entry<String, String[]> stringEntry : parameterMap.entrySet()){
        params.put(stringEntry.getKey(), stringEntry.getValue()[0]);
    }

    Enumeration<String> attributeNames = request.getAttributeNames();

    while (attributeNames.hasMoreElements()){
        String key = attributeNames.nextElement();
        if (request.getAttribute(key) instanceof String){
            params.put(key, request.getAttribute(key).toString());
        }
    }
    Object result = JSONify(params);
    OutputStreamWriter optwriter = new OutputStreamWriter(response.getOutputStream(), "utf-8");
    optwriter.write(JSON.toString(result));
    response.setStatus(200);
    optwriter.flush();
}
 
开发者ID:andysim3d,项目名称:Jxpress,代码行数:24,代码来源:JSONController.java


示例2: 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


示例3: MainController

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
private MainController() {

		getLogger().info("Reading config file from path conf/server.xml");
		ServerXMLConfigReader configReader;
		try {
			configReader = new ServerXMLConfigReader("conf/server.xml");
			socketServerController = new SocketServerController(
					configReader.getSocketClientConfig());
			Map<String, Class<? extends Processor>> processorMap = configReader
					.getProcessorMap();
			this.getSocketServerController().initProcessor(processorMap);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		httpClientController = new HttpClientController();
		json = new JSON();
	}
 
开发者ID:phat-trien-phan-mem-phan-tan,项目名称:dynamicpool,代码行数:20,代码来源:MainController.java


示例4: send

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
public void send(Object data) {
	try {
		PrintWriter out = new PrintWriter(socketClient.getOutputStream(),
				true);
		if (data instanceof String) {
			log.info("SEND MESSAGE {}", data);
			out.println(data);
		} else {
			JSON json = new JSON();
			String message = json.toJSON(data);
			log.info("SEND MESSAGE {}", message);
			out.println(message);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:phat-trien-phan-mem-phan-tan,项目名称:dynamicpool,代码行数:18,代码来源:SocketClientController.java


示例5: NIOSocketServerController

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
public NIOSocketServerController(SocketServerConfig config) {
	this.setConfig(config);
	this.acceptor = new NioSocketAcceptor();

	acceptor.getFilterChain().addLast("logger", new LoggingFilter());
	acceptor.getFilterChain().addLast(
			"codec",
			new ProtocolCodecFilter(new TextLineCodecFactory(Charset
					.forName("UTF-8"))));

	acceptor.setHandler(this);

	acceptor.getSessionConfig().setReadBufferSize(2048);
	acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);

	json = new JSON();
	this.processorManager = new ProcessorManager();
}
 
开发者ID:phat-trien-phan-mem-phan-tan,项目名称:dynamicpool,代码行数:19,代码来源:NIOSocketServerController.java


示例6: ClientMainController

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
private ClientMainController() {
	loadLog4j();
	getLogger().info("Reading config file from path conf/client.xml");
	ServerXMLConfigReader configReader;
	try {
		configReader = new ServerXMLConfigReader("conf/client.xml");
		clientSocketController = new ClientSocketController(
				configReader.getSocketServerConfig());
		Map<String, Class<? extends Processor>> processorMap = configReader
				.getProcessorMap();
		this.getClientSocketController().initProcessor(processorMap);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

	httpClientController = new HttpClientController();
	json = new JSON();
	dispatchers = new ArrayList<BaseEventDispatcher>();
}
 
开发者ID:phat-trien-phan-mem-phan-tan,项目名称:dynamicpool,代码行数:21,代码来源:ClientMainController.java


示例7: 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


示例8: 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


示例9: get

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
@GET
@Path("{" + PATH + ":.*}")
@Produces({MediaType.APPLICATION_JSON})
public Response get(
    @PathParam(PATH) @DefaultValue("UNKNOWN_" + PATH) final String path,
    @QueryParam(OP) @DefaultValue("UNKNOWN_" + OP) final String op
    ) throws IOException {
  LOG.info("get: " + PATH + "=" + path + ", " + OP + "=" + op);

  final Map<String, Object> m = new TreeMap<>();
  m.put(PATH, path);
  m.put(OP, op);
  final String js = JSON.toString(m);
  return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
}
 
开发者ID:apache,项目名称:hbase,代码行数:16,代码来源:JerseyResource.java


示例10: MainFrame

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
/**
 * Create the frame.
 */
public MainFrame() {
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	setBounds(100, 100, 309, 206);
	contentPane = new JPanel();
	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
	setContentPane(contentPane);
	contentPane.setLayout(null);
	
	JButton btnRegisterHost = new JButton("register host");
	btnRegisterHost.setBounds(10, 11, 112, 23);
	contentPane.add(btnRegisterHost);
	
	textField = new JTextField();
	textField.setBounds(143, 12, 112, 20);
	contentPane.add(textField);
	textField.setColumns(10);
	btnRegisterHost.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent arg0) {
			String response = MainController.getInstance().getHttpClientController().regHost();
			System.out.println(response);
			JSON json = new JSON();
			@SuppressWarnings("unchecked")
			Map<String, Object> map = (Map<String, Object>)json.fromJSON(response);
			if(map.containsKey("error")){
				if(map.get("error") == null){
					textField.setText((String)map.get("key"));
				}
			}
		}
	});
}
 
开发者ID:phat-trien-phan-mem-phan-tan,项目名称:dynamicpool,代码行数:36,代码来源:MainFrame.java


示例11: ClientSocketController

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
public ClientSocketController(SocketServerConfig config) {
	socketClientController = new SocketClientController(this);
	processorManager = new ProcessorManager();
	this.config = config;
	jsonSerializer = new JSONSerializer();
	json = new JSON();
}
 
开发者ID:phat-trien-phan-mem-phan-tan,项目名称:dynamicpool,代码行数:8,代码来源:ClientSocketController.java


示例12: doGet

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {
   	response.setContentType("application/json");   
   	PrintWriter out = response.getWriter();
   	try {
   		FormData data = getFormData();
   		String jsonRepresentation = JSON.DEFAULT.toJSON(data);
		out.print(jsonRepresentation);
	} catch (CandybeanException e) {
		throw new IOException(e);
	}
   	out.flush();
}
 
开发者ID:sugarcrm,项目名称:candybean,代码行数:15,代码来源:LoadConfigurationServlet.java


示例13: getExecutionDataAsJSON

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
/**
 * Convenience method. Same as {@link #getExecutionData()}, but returns the map of key/value pairs as a JSON string.
 */
public String getExecutionDataAsJSON() {
	return JSON.toString(this.executionData);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:7,代码来源:RunConfiguration.java


示例14: setScriptParams

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
public UpdateRequestBuilder setScriptParams(Map params) {
	body().put("params", JSON.toString(params));
	return this;
}
 
开发者ID:winterstein,项目名称:elasticsearch-java-client,代码行数:5,代码来源:UpdateRequestBuilder.java


示例15: 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


示例16: 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


示例17: toString

import org.eclipse.jetty.util.ajax.JSON; //导入依赖的package包/类
@Override
public String toString() {
	return "{\"header\":\""+StringEscapeUtils.escapeJava(header)+"\"" + ",\"formFields\":"+JSON.DEFAULT.toJSON(formFields)+
			"}";
}
 
开发者ID:sugarcrm,项目名称:candybean,代码行数:6,代码来源:FormData.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IndicesStatusResponse类代码示例发布时间:2022-05-22
下一篇:
Java PropertyMap类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap