json java simple-json
http://code.google.com/p/json-simple/wiki/EncodingExamples#Example_1-1_-_Encode_a_JSON_object
javac -cp ./json-simple.jar SplitDemo.java
java -cp _CLASSPATH:./json-simple.jar SplitDemo
public class QueryAttribute implements JSONStreamAware {
private String query;
private String cat;
private int guanwang;
private String icon;
private String entity_name;
private double score;
private String clkurl;
public QueryAttribute(String query, double score, String cat,
String entity_name, int guanwang, String icon, String clkurl) {
this.query = query;
this.cat = cat;
this.entity_name = entity_name;
this.score = score;
this.guanwang = guanwang;
this.icon = icon;
this.clkurl = clkurl;
}
public void writeJSONString(Writer out) throws IOException {
LinkedHashMap obj = new LinkedHashMap();
obj.put("query", query);
obj.put("score", score);
obj.put("cat", cat);
obj.put("ename", entity_name);
obj.put("gw", guanwang);
obj.put("icon", icon);
obj.put("clkurl", clkurl);
JSONValue.writeJSONString(obj, out);
}
}
parser
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.JSONValue;
import java.util.*;
public class Segment
{
public static void main(String[] args)
{
String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
Object obj = JSONValue.parse(s);
JSONArray array = (JSONArray)obj;
System.out.println(array.get(0));
System.out.println(array.get(1));
System.out.println();
JSONObject obj2 = (JSONObject)array.get(1);
System.out.println("=============field \"1\"=======");
System.out.println(obj2.get("1"));
System.out.println(obj); s = "{}";
obj = JSONValue.parse(s);
System.out.println(obj); s = "[5,]";
obj = JSONValue.parse(s);
System.out.println(obj); s = "[5,,2]";
obj = JSONValue.parse(s);
System.out.println(obj);
}
}
json java simple-json的更多相关文章
- JSON — Java与JSON数据互转
转换时Bean所要求的: 被转换的Bean必需是public的. Bean被转换的属性一定要有对应的get方法,且一定要是public的. Bean中不能用引用自身的this的属性,否则运行时出现et ...
- Java转json
一.json介绍 1. 作用:JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,是存储和交换文本信息的语法. 2.json以key-value的格式书写,数 ...
- 几种Java的JSON解析库速度对比
java中哪个JSON库的解析速度是最快的? JSON已经成为当前服务器与WEB应用之间数据传输的公认标准,不过正如许多我们所习以为常的事情一样,你会觉得这是理所当然的便不再深入思考 了.我们很少会去 ...
- Introduction to Structured Data json的2种形式 JAVA解析JSON数据 - JsonArray JsonObject
https://developers.google.com/search/docs/guides/intro-structured-data Structured data refers to kin ...
- Java中json的构造和解析
什么是 Json? JSON(JvaScript Object Notation)(官网网站:http://www.json.org/)是 一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机 ...
- Java的Json解析包FastJson使用
阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备如下特征:速度最快,测试表明,fastjson具有极快的性能,超越任其他的Java Json parser. ...
- java解析json
1:下载另外一个Java的小包就可以了: http://www.JSON.org/java/json_simple.zip 里面有源码和文档例题和编程的lib包:编程只需要json_simple.ja ...
- PHP、Java输出json格式数据
PHP 输出json. $result = mysql_query($sql); //查询结果 $users=array(); $i=0; while($row=mysql_fetch_array ...
- 使用json-lib进行Java和JSON之间的转换 [转]
[转] http://www.cnblogs.com/mailingfeng/archive/2012/01/18/2325707.html 1. json-lib是一个java类库,提供将Java对 ...
- Java集合 Json集合之间的转换
1. Java集合转换成Json集合 关键类:JSONArray jsonArray = JSONArray.fromObject(Object obj); 使用说明:将Java集合对象直接传进JSO ...
随机推荐
- rails中一个窗体多个模型——fields_for
详细参考 http://railscasts.com/episodes/73-complex-forms-part-1中part-1.2.3部分 借助field_for可以生成表单来处理两个或更多模型 ...
- 问题:JsonConvert;结果:JSON详解
JSON详解 JSON的全称是”JavaScript Object Notation”,意思是JavaScript对象表示法,它是一种基于文本,独立于语言的轻量级数据交换格式.XML也是一种数据交换格 ...
- numpy.zeros(shape, dtype=float, order='C')
numpy.zeros Return a new array of given shape and type, filled with zeros. Parameters: shape : int o ...
- python 爬虫 之BeautifulSoup
BeautifulSoup是一个模块,该模块用于接收一个HTML或XML字符串,然后将其进行格式化,之后便可以使用他提供的方法进行快速查找指定元素,从而使得在HTML或XML中查找指定元素变得简单. ...
- css之布局
布局一直是页面制作很重要的部分,有个良好的布局不仅在页面上呈现很好的效果,还对后续功能扩展有重要的作用.本文主要讨论一下几种布局: 水平居中布局 垂直居中布局 多列布局 自适应布局 stracky-f ...
- CSS3新增的伪类
Element1 ~ element2:选择前面有element1的所有element2元素 [attr ^= val] 属性值以val开头的元素 [attr $= val] 属性值以val结尾的元素 ...
- 点云视窗类CloudViewer
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=149 点云视窗类CloudViewer是简单显示点云的可视化工具类,可以让用 ...
- ARC097C K-th Substring
传送门 题目 You are given a string s. Among the different substrings of s, print the K-th lexicographical ...
- java之字符
参考http://how2j.cn/k/number-string/number-string-character/323.html 保存一个字符的时候使用char package character ...
- HTML5+JavaScript动画基础 完整版 中文pdf扫描版
<HTML5+JavaScript动画基础>包括了基础知识.基础动画.高级动画.3D动画和其他技术5大部分,分别介绍了动画的基本概念.动画的JavaScript基础.动画中的三角学.渲染技 ...