如何把一个java数组解析成json数组
1个回答
2016-08-13 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
import net.sf.json.JSONArray;
public class TestJson
{
public static void main(String []args)
{
String json = "[{\"a\":\"111\",\"b\":\"222\",\"c\":\"333\"},{\"a\":\"1000\",\"b\":\"2000\",\"c\":\"000\"},{\"a\":\"999\",\"b\":\"300\",\"c\":\"700\"}]";
JSONArray jsonArr = JSONArray.fromObject(json);
String a[] = new String[jsonArr.size()];
String b[] = new String[jsonArr.size()];
String c[] = new String[jsonArr.size()];
for (int i = 0; i < jsonArr.size(); i++) {
a[i] = jsonArr.getJSONObject(i).getString("a");
b[i] = jsonArr.getJSONObject(i).getString("b");
c[i] = jsonArr.getJSONObject(i).getString("c");
}
for (int i = 0; i < c.length; i++) {
System.out.print(a[i]+" ");
System.out.print(b[i]+" ");
System.out.print(c[i]);
System.out.println();
}
}
}
public class TestJson
{
public static void main(String []args)
{
String json = "[{\"a\":\"111\",\"b\":\"222\",\"c\":\"333\"},{\"a\":\"1000\",\"b\":\"2000\",\"c\":\"000\"},{\"a\":\"999\",\"b\":\"300\",\"c\":\"700\"}]";
JSONArray jsonArr = JSONArray.fromObject(json);
String a[] = new String[jsonArr.size()];
String b[] = new String[jsonArr.size()];
String c[] = new String[jsonArr.size()];
for (int i = 0; i < jsonArr.size(); i++) {
a[i] = jsonArr.getJSONObject(i).getString("a");
b[i] = jsonArr.getJSONObject(i).getString("b");
c[i] = jsonArr.getJSONObject(i).getString("c");
}
for (int i = 0; i < c.length; i++) {
System.out.print(a[i]+" ");
System.out.print(b[i]+" ");
System.out.print(c[i]);
System.out.println();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |