JSONObject 读取json问题
json格式是这样的:[{"key":"a","value":"1"},{"key":"b","value":"2"}]怎么读取呢...
json格式是这样的:[{"key":"a","value":"1"},{"key":"b","value":"2"}]
怎么读取呢 展开
怎么读取呢 展开
展开全部
package image;
import java.util.Iterator;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class FrameTest
{
public static void main ( String[] Args )
{
String json = "[{\"key\":\"a\",\"value\":\"1\"},{\"key\":\"b\",\"value\":\"2\"}]";
JSONArray ja = JSONArray.fromString (json);
for ( int i = 0; i < ja.length (); i++ )
{
JSONObject jo = JSONObject.fromObject (ja.get (i));
Iterator<?> it = jo.keys ();
while (it.hasNext ())
{
System.out.print (jo.get ((String) it.next ()) + " ");
}
}
}
}
展开全部
<script type="text/javascript" src="jq/js/jquery.js"></script>
<script type="text/javascript">
$(function(){
var a=[{"key1":"a","value1":"1"},{"key2":"b","value2":"2"}]
alert(a[1].key2)
})
</script>
<script type="text/javascript">
$(function(){
var a=[{"key1":"a","value1":"1"},{"key2":"b","value2":"2"}]
alert(a[1].key2)
})
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void main(String[] args) {
String str="[{"key":"a","value":"1"},{"key":"b","value":"2"}]";
JSONObject jsonList= JSONObject.fromObject(str);
List list=(List ) JSONObject.toBean(jsonList, List.class);
System.out.println(list);
}
转换成List<Map<String,String>>类型
String str="[{"key":"a","value":"1"},{"key":"b","value":"2"}]";
JSONObject jsonList= JSONObject.fromObject(str);
List list=(List ) JSONObject.toBean(jsonList, List.class);
System.out.println(list);
}
转换成List<Map<String,String>>类型
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var data = [{"key":"a","value":"1"},{"key":"b","value":"2"}];
var key = data[0].key;
var value= data[0].value;
var key = data[0].key;
var value= data[0].value;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询