使用Json,可以下载如下所示的6个Jar包

整个工程目录结构如下:

简单的用法:

package json;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject; public class JsonTest { public static void main(String[] args) {
//1、输出Json字符串
JSONObject container1 = new JSONObject();
container1.put("ClassName", "1班");
System.out.println(container1.toString()); //2、输出Json字符串 + Json数组
JSONArray className =new JSONArray();
className.add("2班");
className.add("3班");
container1.put("classname", className);
System.out.println(container1.toString()); //3、输出Json字符串 + Json数组 + Json字符串
JSONObject classInfo = new JSONObject();
classInfo.put("stuCount", 50);
classInfo.put("leader", "rah");
container1.put("classInfo", classInfo);
System.out.println(container1); //4、字符串 转为 Json数组对象
String jsonMessage =
"[{'num':'成绩', '外语':88, '历史':65, '地理':99, 'object':{'aaa':'1111','bbb':'2222','cccc':'3333'}}," +
"{'num':'兴趣', '外语':28, '历史':45, '地理':19, 'object':{'aaa':'11a11','bbb':'2222','cccc':'3333'}}," +
"{'num':'爱好', '外语':48, '历史':62, '地理':39, 'object':{'aaa':'11c11','bbb':'2222','cccc':'3333'}}]"; JSONArray test = JSONArray.fromObject(jsonMessage);
System.out.println(test.toString());
//获取Json数组的某个索引的值
System.out.println(test.get(0));
System.out.println(test.get(1));
} }

Json使用示例的更多相关文章

  1. jQuery中读取json文件示例代码

    json文件是一种轻量级的数据交互格式.一般在jquery中使用getJSON()方法读取,具体示例代码如下,感兴趣的朋友可以参考下哈,希望可以帮助到你   json文件是一种轻量级的数据交互格式.一 ...

  2. form 转json最佳示例

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. C# List集合转Json字符串示例代码

    将list集合转换为Json字符串简单实现代码: public static string GetJosn(List<CalendarInfo> list) { string jsonSt ...

  4. 一个用httpPost,get访问外网接口,参数json,返回json的示例

    package com.royal.util; import java.io.BufferedReader;import java.io.DataInputStream;import java.io. ...

  5. ajax返回json数据示例

    前端发送请求与接收数据: $.ajax({        type : "post",        url : "/queryStudent",       ...

  6. PHP Echarts Ajax Json柱形图示例

    <?php $server = '127.0.0.1'; $user = 'root'; $password = ''; $database = 'yiibaidb'; $conn = new ...

  7. jsp+ajax+servlet+jquery从后台取json数据示例

    <span style="font-size:18px;"><%@ page language="java" import="jav ...

  8. Node.js 使用angularjs取得Nodejs http服务端返回的JSON数组示例

    server.js代码: // 内置http模块,提供了http服务器和客户端功能(path模块也是内置模块,而mime是附加模块) var http=require("http" ...

  9. Node.js 使用jQuery取得Nodejs http服务端返回的JSON数组示例

    server.js代码: // 内置http模块,提供了http服务器和客户端功能(path模块也是内置模块,而mime是附加模块) var http=require("http" ...

随机推荐

  1. python 多进程和多线程

    在计算大量数据时,可以使用多进程 多线程机制来加速计算 多进程 import multiprocessing import os def run_proc(name): print('Child pr ...

  2. firewalld管理防火墙常用命令

    1.查看防火墙的状态 [root@localhost HMK]# firewall-cmd --state 查看防火墙的运行状态 not running [root@localhost HMK]# s ...

  3. SpringData Redis

    Redis spring-data-redis

  4. clustering

    搞了将近一年的单细胞,聚类也是自认为得心应手了,自信满满. 但是多半是跑软件,对聚类的深层次的思想不甚了了. Google了一下clustering,看了一篇文章,突然了解到了clustering的算 ...

  5. 安装Jade

    1.安装node.js 直接有安装程序:http://nodejs.cn/ 2.安装git 直接的安装程序:http://jingyan.baidu.com/article/90895e0fb3495 ...

  6. hdu-2421 Deciphering Password 数学姿势

    给定A,B,对于A^B的每一个因子,M为其因子的因子数的三次方求和. 容易推导得出A^B的每一个因子都是A的质因子的组合(质因子可重复利用),其因子数自然等于所使用的每个质因子的数量乘积. 假设A由质 ...

  7. centOS 6.5采用python+nginx+uwsgi实现爬金十财经日历

    上一篇中有关于安装nginx.python.uwsgi的过程,这里不再重述.下面是有关在具体布署中的一些过程和问题处理 一.因为用到了bs4(BeautifulSoup)\paste\lxml所以这些 ...

  8. 59 Cookie 与 Session

    Cookie Cookie是由服务器创建,然后通过响应发送给客户端的一个键值对. 客户端会保存Cookie,并会标注出Cookie的来源(哪个服务器的Cookie). 当客户端向服务器发出请求时会把所 ...

  9. PHP单例模式实例,连接数据库对类的引用

    <?php//单例模式连接数据库class pzhang{ static private $instance; private static $config; private $dbase = ...

  10. 6月6 Smarty练习----设置题目及打印试卷

    所需要的数据库表格:shiti, shititimu, timu, kemu, xuanxiang  考试试题的设置: 考试试题后台:ksset.php <?php include(" ...