In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
本篇内容主要讲解"json数组怎么将字符串转list集合",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"json数组怎么将字符串转list集合"吧!
1.json字符串
json字符串与普通的字符串没有任何特殊的地方,但是之所以称为json字符串是因为,这个字符串符合我们之前介绍的语法规则。
2.json数组形式字符串转换为List的8种方法
package com.zkn.newlearn.json; import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONArray;import com.alibaba.fastjson.JSONObject; import java.util.List;import java.util.Map; /** * Created by zkn on 2016/8/22. */public class JsonToMapTest02 { public static void main(String[] args){ String strArr = "[{\"0\":\"zhangsan\",\"1\":\"lisi\",\"2\":\"wangwu\",\"3\":\"maliu\"}," + "{\"00\":\"zhangsan\",\"11\":\"lisi\",\"22\":\"wangwu\",\"33\":\"maliu\"}]"; //第一种方式 List listObjectFir = (List) JSONArray.parse(strArr); System.out.println("利用JSONArray中的parse方法来解析json数组字符串"); for(Map mapList : listObjectFir){ for (Map.Entry entry : mapList.entrySet()){ System.out.println( entry.getKey() + " " +entry.getValue()); } } //第二种方式 List listObjectSec = JSONArray.parseObject(strArr,List.class); System.out.println("利用JSONArray中的parseObject方法并指定返回类型来解析json数组字符串"); for(Map mapList : listObjectSec){ for (Map.Entry entry : mapList.entrySet()){ System.out.println( entry.getKey() + " " +entry.getValue()); } } //第三种方式 JSONArray listObjectThir = JSONArray.parseArray(strArr); System.out.println("利用JSONArray中的parseArray方法来解析json数组字符串"); for(Object mapList : listObjectThir){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " +((Map.Entry)entry).getValue()); } } //第四种方式 List listObjectFour = JSONArray.parseArray(strArr,Map.class); System.out.println("利用JSONArray中的parseArray方法并指定返回类型来解析json数组字符串"); for(Object mapList : listObjectFour){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " +((Map.Entry)entry).getValue()); } } //第五种方式 JSONArray listObjectFifth = JSONObject.parseArray(strArr); System.out.println("利用JSONObject中的parseArray方法来解析json数组字符串"); for(Object mapList : listObjectFifth){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " +((Map.Entry)entry).getValue()); } } //第六种方式 List listObjectSix = JSONObject.parseArray(strArr,Map.class); System.out.println("利用JSONObject中的parseArray方法并指定返回类型来解析json数组字符串"); for(Object mapList : listObjectSix){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " +((Map.Entry)entry).getValue()); } } //第七种方式 JSONArray listObjectSeven = JSON.parseArray(strArr); System.out.println("利用JSON中的parseArray方法来解析json数组字符串"); for(Object mapList : listObjectSeven){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " +((Map.Entry)entry).getValue()); } } //第八种方式 List listObjectEigh = JSONObject.parseArray(strArr,Map.class); System.out.println("利用JSON中的parseArray方法并指定返回类型来解析json数组字符串"); for(Object mapList : listObjectEigh){ for (Object entry : ((Map)mapList).entrySet()){ System.out.println(((Map.Entry)entry).getKey() + " " +((Map.Entry)entry).getValue()); } } }}到此,相信大家对"json数组怎么将字符串转list集合"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.