zoukankan
html css js c++ java
复杂JSON字符串解析,可以少走弯路
发现一个好文章:装载至
http://www.verejava.com/?id=17174254038220
package com.json5;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class Test
{
public static void main(String[] args)
{
/*
1.将下面的JSON字符串 解析并打印出来
{name:'李俊',age:25,address:{description:'北京 回龙观 新龙城',floor:10},like:['唱歌','画画','旅游']}
*/
String str="{name:'李俊',age:25,address:{description:'北京 回龙观 新龙城',floor:10},like:['唱歌','画画','旅游']}";
//JSONObject 解析
try
{
JSONObject jsonObj=new JSONObject(str);
String name=jsonObj.getString("name");
int age=jsonObj.getInt("age");
System.out.println(name+","+age);
//地址是 JSONObject
JSONObject addressObj=jsonObj.getJSONObject("address");
String description=addressObj.getString("description");
int floor=addressObj.getInt("floor");
System.out.println(description+","+floor);
//爱好是 JSONArray
JSONArray likeArray=jsonObj.getJSONArray("like");
for(int i=0;i<likeArray.length();i++)
{
String value=likeArray.getString(i);
System.out.println(value);
}
} catch (JSONException e)
{
e.printStackTrace();
}
}
}
查看全文
相关阅读:
二元函数求一定区间上的最大值问题
LOF异常检测算法实现
失效项目总代码汇总
layui弹出层layer.open 中的content问题
分治算法基本原理和实践
Android 文件存储浅析
详解 CmProcess 跨进程通信的实现
View Animation 运行原理解析
margin-top失效及解决办法
vue自定义移动端touch事件之点击、滑动、长按事件
原文地址:https://www.cnblogs.com/youxiu326/p/10540781.html
最新文章
CSS3 @keyframes 规则
H5调用原生APP的js方法
setTimeout 和 setInterval 的区别及相互模拟
jQuery 旋转插件 jqueryrotate 用法详解
alert 弹窗去掉上方 title 网址域名
移动端H5 转盘抽奖
解决手机(移动端)点击事件失效问题
请求服务器报错 Access-Control-Allow-Origin
vue加载显示{{xxx}}的解决方法
jquery 正则表达式验证(中文名称、手机号)
热门文章
快速最优化函数
数据比赛项目数据可视化模块代码大全
时间序列分析模型
京东数据开发工程师笔试初版
kmeans改进版聚类算法
python绘制箱线图
python实现多条柱状图对比输出?
寻找子数组在数组中的索引号?
多算法融合2_SVM
二维爬山扫描算法求最大值
Copyright © 2011-2022 走看看