遍历json数组

//遍历json数组

String json1 = "{data:[{name:‘Wallace‘},{name:‘Grommit‘}]}";

jsonObjSplit = new JSONObject(json1);

JSONArray ja = jsonObjSplit.getJSONArray("data");

for (int i = 0; i < ja.length(); i++) {

  JSONObject jo = (JSONObject) ja.get(i);

  System.out.println(jo.get("name"));

}

//JSONObject遍历json对象

String json2 = "{name:‘Wallace‘,age:15}";

jsonObj = new JSONObject(json2);

for (Iterator iter = jsonObj.keys(); iter.hasNext();){

  String key = (String)iter.next();

  System.out.println(jsonObj .getString(Key));

时间: 2024-12-15 00:19:53

遍历json数组的相关文章

jquery $.each遍历json数组方法

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head>  <meta http-equiv="content-

遍历json数组的常用方式

遍历json对象数组 1. 传统数组遍历 var data=[{"name":"zhangsan","age":12},{"name":"lisi","age":22}]; for(var i=0;i<data.length;i++) { alert(data[i].name+"--"+data[i].age); } 2.key/value map方式遍历 ke

Json格式循环遍历,Json数组循环遍历

Json格式数据如何遍历,这里我们可以用for..in实现 例如最简单的json格式 var json1 = { 'name' : '小钻风' , 'age' : 25 , 'handsome' : 'yes' }; for( var key in json1 ){ console.log( key+' : '+json1[key] ); } 再来个升级版的,如下 var json1 = { 'name' : ['echo' , '小钻风' , '妈卖批' , '小白兔'], 'age' : [

$.each遍历json数组

1.遍历单层json数组 我们把idx和obj都打印出来看看,到底是什么东西 var json1 =[{"id":"1","tagName":"apple"}, {"id":"2","tagName":"orange"}, {"id":"3","tagName":"banana&

【转】 jquery遍历json数组方法

$(function () { var tbody = ""; //------------遍历对象 .each的使用------------- //对象语法JSON数据格式(当服务器端回调回来的对象数据格式是json数据格式,必须保证JSON的格式要求,回调的对象必须使用eval函数进行转化(否则将得不到Object).本文不作详细介绍服务器端回调的数据问题,我们将直接自定义对象) var obj = [{ "name": "项海军", &qu

juery中循环遍历json数组

var dataList=[]; var stock0={stockcode:"007758",stockname:"商业政7",state:"1"}; var stock1={stockcode:"006658",stockname:"材料政8",state:"1"}; var stock2={stockcode:"023758",stockname:"深

jQuery遍历Json数组

var jsonArray=  [{ "name": "张三", "password": "123456"},{ "name": "李四", "password": "123456"}]; $.each(obj, function (n, value) { n:数组中的位置: value.name:张三.李四 value.password:1234

Json数组的遍历

[{"productid":"1","sortindex":"2"},{"productid":"2","sortindex":"3"}] 在JSON中,有两种结构:对象和数组. 1.对象 一个对象以“{”开始,“}”结束.每个“key”后跟一“:”,“‘key/value’ 对”之间运用 “,”分隔. packJson = {"name

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

server.js代码: // 内置http模块,提供了http服务器和客户端功能(path模块也是内置模块,而mime是附加模块) var http=require("http"); // 创建服务器,创建HTTP服务器要调用http.createServer()函数,它只有一个参数,是个回调函数,服务器每次收到http请求后都会调用这个回调函数.服务器每收到一条http请求,都会用新的request和response对象触发请求函数. var server=http.createS