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 ...
随机推荐
- TModJS:README
ylbtech-TModJS:README 1.返回顶部 1. TmodJS 项目已经停止维护,请使用更好的代替方案:art-template-loader TmodJS(原名 atc)是一个简单易用 ...
- linux->windows主动推送文件同步目录数据 linux-windows数据目录同步
1 .windows下安装openssh for windows工具,下载地址 https://www.mls-software.com/opensshd.html 2.修改openssh安装目录下e ...
- springMVC绑定json参数之二(2.1.1)
二.springmvc 接收不同格式的json字符串 1.首先扫盲几个知识点: 例子如下: 前台传递json对象(这里uu[0]的名字uu要和Test对象中的属性List<User>名称对 ...
- Android的系统结构简述
(该图片来自网络) Android系统结构主要分为四层,从上到下依次为,Application层,Application Framework层,lib层,Linux kernel层,下面对这四层进行简 ...
- crontab简易入门
前言 crontab是Unix和Linux用于设置周期性被执行的指令,是互联网很常用的技术,很多任务都会设置在crontab循环执行,如果不使用crontab,那么任务就是常驻程序,这对你的程序要求比 ...
- BLAST在Windows系统中本地化
简介 NCBI除了提供在线的Web BLAST序列比对服务外,还提供FTP方式下载序列比对工具.这允许在本地平台上针对从NCBI下载或本地创建的数据库执行BLAST搜索.这些实用程序没有图形用户界面, ...
- String与字符数组
public class Example { static String str = new String("good"); static char[] ch = {'a','b' ...
- 29.极具破坏力的DDoS:浅析其攻击及防御
一.DDoS的概念 1.什么是“DDoS”? DDoS:Distributed Denial of Service(分布式拒绝服务)攻击指借助于客户/服务器技术,将多个计算机联合起来作为攻击平台,对一 ...
- 解决IIS出现的问题
- Win7常用但是被忽略的快捷键
General keyboard shortcuts 1.Ctrl + Right Arrow Move the cursor to the beginning of the next word 向 ...