java 如何对由json对象构成的数组形式的字符串进行遍历?

时间:2022-01-27 20:22:41
 

1.情景展示

  现在已知字符串为:

[{"name":"微微笑","img":"http://zos.alipayobjects.com/rmsportal/TbDyUuhymEDMHWiKAqUw.png"},{"name":"羞羞","img":"http://zos.alipayobjects.com/rmsportal/QqlNIwJLFrztbcePzojb.png"},{"name":"吐舌头","img":"http://zos.alipayobjects.com/rmsportal/mphUsGFrBDfVixNLigpy.png"},{"name":"哈哈大笑","img":"http://zos.alipayobjects.com/rmsportal/bKZHSElGKnVVEAjZsKEm.png"},{"name":"安慰一下","img":"http://zos.alipayobjects.com/rmsportal/iUOoiEMFnCcOBpBYSbcA.png"},{"name":"抱抱","img":"http://zos.alipayobjects.com/rmsportal/aJzJixNlsdWRPtCqlFgG.png"},{"name":"耶","img":"http://zos.alipayobjects.com/rmsportal/DshwVWFCrJqXoAWCFYxd.png"},{"name":"你牛","img":"http://zos.alipayobjects.com/rmsportal/VVkRWduhMRZUEayYsydn.png"},{"name":"亲一个","img":"http://zos.alipayobjects.com/rmsportal/pFfAnQYxWTsaBaOrIiGy.png"},{"name":"花痴","img":"http://zos.alipayobjects.com/rmsportal/OgOMiGBaLEsKVjmywQSY.png"},{"name":"算下账","img":"http://zos.alipayobjects.com/rmsportal/gAnUTYnuVBhELZvgnQhC.png"},{"name":"拜拜","img":"http://zos.alipayobjects.com/rmsportal/hmHqZNsDpotoUbOaPwoU.png"},{"name":"色情狂","img":"http://zos.alipayobjects.com/rmsportal/jfCpZgEangcUhxtWNjBn.png"},{"name":"无聊发呆","img":"http://zos.alipayobjects.com/rmsportal/GrVGDRymXemQzzBkcuoi.png"},{"name":"小样","img":"http://zos.alipayobjects.com/rmsportal/etcvwaipQIrfWWPDizgE.png"},{"name":"摇头","img":"http://zos.alipayobjects.com/rmsportal/OGirQyCBgWMjcdSNjfKu.png"},{"name":"傻傻笑","img":"http://zos.alipayobjects.com/rmsportal/rDjBdQzqQimXkivksSvN.png"},{"name":"不会吧","img":"http://zos.alipayobjects.com/rmsportal/JaYhdfsIQrjsTEqqPoiv.png"},{"name":"困了","img":"http://zos.alipayobjects.com/rmsportal/emSaBGCQjqglinCAoOWQ.png"},{"name":"眼泪掉下来","img":"http://zos.alipayobjects.com/rmsportal/YqhwlIJfOpAVFpDstsXe.png"},{"name":"痛哭","img":"http://zos.alipayobjects.com/rmsportal/iRSIswAaEwrFgJjJnCrk.png"},{"name":"鄙视你","img":"http://zos.alipayobjects.com/rmsportal/IpWUDFIYjrowojLtidKo.png"},{"name":"大怒","img":"http://zos.alipayobjects.com/rmsportal/eWVMzvFpQnWXNqXVTpuh.png"},{"name":"学习雷锋","img":"http://zos.alipayobjects.com/rmsportal/OLEdTsPLUuXymHzhaIAp.png"},{"name":"约架啊","img":"http://zos.alipayobjects.com/rmsportal/TDHmPgepgvNacJuEQxbW.png"},{"name":"惊声尖叫","img":"http://zos.alipayobjects.com/rmsportal/jRzlKZZmrHUPplhwzUif.png"},{"name":"成交","img":"http://zos.alipayobjects.com/rmsportal/FiQetAvYpWNnlnljTMwi.png"},{"name":"拍手","img":"http://zos.alipayobjects.com/rmsportal/NdlnyAZlyzwkYOmyKPET.png"},{"name":"愉快","img":"http://zos.alipayobjects.com/rmsportal/fizHirPrEYbZylPXFfyf.png"},{"name":"撇嘴","img":"http://zos.alipayobjects.com/rmsportal/YcfeFpumJriXrTsLyPGR.png"},{"name":"色","img":"http://zos.alipayobjects.com/rmsportal/tIiReQQiOtcUCaudHJfn.png"},{"name":"傻笑","img":"http://zos.alipayobjects.com/rmsportal/bljVgILMsFSBvdypFMfR.png"},{"name":"得意","img":"http://zos.alipayobjects.com/rmsportal/BlfPFKcmCBxRDAoNTSzW.png"},{"name":"流泪","img":"http://zos.alipayobjects.com/rmsportal/vHwkArAhUlwQSoEVGNbm.png"},{"name":"色眯眯","img":"http://zos.alipayobjects.com/rmsportal/CDejqiJYJPCztsuefYyt.png"},{"name":"闭嘴","img":"http://zos.alipayobjects.com/rmsportal/hayTisHQQBwHCxzOnLFi.png"},{"name":"可怜","img":"http://zos.alipayobjects.com/rmsportal/WomzNePHtafzoBhSflBy.png"},{"name":"亲亲","img":"http://zos.alipayobjects.com/rmsportal/MSIFcsNcthTkTGdcQFvZ.png"},{"name":"无聊","img":"http://zos.alipayobjects.com/rmsportal/tTjSunKdTxsEYiLsMfKY.png"},{"name":"发怒","img":"http://zos.alipayobjects.com/rmsportal/BHdbDLnkhQfJZXIssRMB.png"},{"name":"做鬼脸","img":"http://zos.alipayobjects.com/rmsportal/EEdQAFozQudOURwLxmJT.png"},{"name":"呲牙","img":"http://zos.alipayobjects.com/rmsportal/OptBofCVNBfMmqFiVOao.png"},{"name":"难过","img":"http://zos.alipayobjects.com/rmsportal/RHJhmkZCovuNjWxaifJw.png"},{"name":"抢劫","img":"http://zos.alipayobjects.com/rmsportal/QHZQcHHCYuLvLGienwXT.png"},{"name":"抠鼻","img":"http://zos.alipayobjects.com/rmsportal/eZmlONTSMxKCKaXpFiyy.png"},{"name":"冷汗","img":"http://zos.alipayobjects.com/rmsportal/YMkmgOUlhjTQhesBEtJp.png"},{"name":"阴险","img":"http://zos.alipayobjects.com/rmsportal/iDCAEYKkqywAHGsetYlL.png"},{"name":"竖中指","img":"http://zos.alipayobjects.com/rmsportal/hjGuxwUDEyTkjXUFRSQd.png"},{"name":"鄙视","img":"http://zos.alipayobjects.com/rmsportal/XhDuTHhCfdHmAemrPTAu.png"},{"name":"抓狂","img":"http://zos.alipayobjects.com/rmsportal/jfSiTeJEalHSWxuSbgqP.png"},{"name":"偷笑","img":"http://zos.alipayobjects.com/rmsportal/euzSnRyBmrMciYzTjDyX.png"},{"name":"敲打","img":"http://zos.alipayobjects.com/rmsportal/HyZJVaideowUoLeYQSpz.png"},{"name":"白眼","img":"http://zos.alipayobjects.com/rmsportal/pXVjDURZUWEFDanBdAeN.png"},{"name":"吐血","img":"http://zos.alipayobjects.com/rmsportal/PpjzXzOMeAnjMIhAYwGc.png"},{"name":"大笑","img":"http://zos.alipayobjects.com/rmsportal/wCNEOMxiXaAuAJTkurNL.png"},{"name":"尴尬","img":"http://zos.alipayobjects.com/rmsportal/OjQZbjiXxsRwQhYwweKa.png"},{"name":"困","img":"http://zos.alipayobjects.com/rmsportal/IuRNVaBtnXJkJUiaUXNx.png"},{"name":"惊恐","img":"http://zos.alipayobjects.com/rmsportal/BElZbmLJFfQTAfVcLiDN.png"},{"name":"流汗","img":"http://zos.alipayobjects.com/rmsportal/nmaknEdnQbfpPvxFuRcZ.png"},{"name":"憨笑","img":"http://zos.alipayobjects.com/rmsportal/mJYqVPZlCXjPbCESDTMw.png"},{"name":"休闲","img":"http://zos.alipayobjects.com/rmsportal/tjyOfwKxDLOkodgBbAxj.png"},{"name":"大哭","img":"http://zos.alipayobjects.com/rmsportal/MjypprGUjGScqJhCdoLO.png"},{"name":"奋斗","img":"http://zos.alipayobjects.com/rmsportal/cbcsvsSpYzOWZqemmpWL.png"},{"name":"咒骂","img":"http://zos.alipayobjects.com/rmsportal/kOMZoaGOwqeRBuQpTlMn.png"},{"name":"疑问","img":"http://zos.alipayobjects.com/rmsportal/zxdZgsOZKShCTdRnOwyX.png"},{"name":"晕","img":"http://zos.alipayobjects.com/rmsportal/WHTyMiMKqBOsuvgHHoUO.png"},{"name":"震惊","img":"http://zos.alipayobjects.com/rmsportal/qnmbjuebnptBheOjIMqx.png"},{"name":"疯了","img":"http://zos.alipayobjects.com/rmsportal/MLuTFzLImRSIHYQTFpfU.png"},{"name":"嘘","img":"http://zos.alipayobjects.com/rmsportal/HyxOAnpMsbRXRZTWHJVo.png"},{"name":"露齿笑","img":"http://zos.alipayobjects.com/rmsportal/MyFumBgjcXHewLaWzoeM.png"},{"name":"衰","img":"http://zos.alipayobjects.com/rmsportal/KgRwkvdcyAuYPDkFEtSD.png"},{"name":"骷髅","img":"http://zos.alipayobjects.com/rmsportal/wmrIsvpcRAArNQWQOzdn.png"},{"name":"骂人","img":"http://zos.alipayobjects.com/rmsportal/aeluFDqOTuqlAJStPnwX.png"},{"name":"睡","img":"http://zos.alipayobjects.com/rmsportal/OfCOALFWdAiakiYDkWVW.png"},{"name":"再见","img":"http://zos.alipayobjects.com/rmsportal/ZycZvaDHdFIFlAovCxtS.png"},{"name":"笑哭","img":"http://zos.alipayobjects.com/rmsportal/TyIBlJubSAAPCdRmQdGw.png"},{"name":"擦汗","img":"http://zos.alipayobjects.com/rmsportal/IaHstwqoTVMRLGQAerDe.png"},{"name":"飞吻","img":"http://zos.alipayobjects.com/rmsportal/rhTJPuWSFknKCPCXYRwW.png"},{"name":"爱慕","img":"http://zos.alipayobjects.com/rmsportal/VnejNVxdfsxvNYnXktlQ.png"},{"name":"惊讶","img":"http://zos.alipayobjects.com/rmsportal/MXfoCtzXulpZBXULFtCy.png"},{"name":"糗大了","img":"http://zos.alipayobjects.com/rmsportal/RairwMrxBfbZVjhqlWNh.png"},{"name":"坏笑","img":"http://zos.alipayobjects.com/rmsportal/kkeSAqIcPIojdFTWplKg.png"},{"name":"左哼哼","img":"http://zos.alipayobjects.com/rmsportal/gLbJITQuiQOZCbVlKOfg.png"},{"name":"右哼哼","img":"http://zos.alipayobjects.com/rmsportal/LbquIrqjViaajMvOWAio.png"},{"name":"哈欠","img":"http://zos.alipayobjects.com/rmsportal/dDauYdGBkWHOTuIbrgPx.png"},{"name":"吐","img":"http://zos.alipayobjects.com/rmsportal/CFMNDmAcxXjjVUoTWmcb.png"},{"name":"委屈","img":"http://zos.alipayobjects.com/rmsportal/gcHkEsBDrRQVCtAsNRAv.png"},{"name":"微笑","img":"http://zos.alipayobjects.com/rmsportal/FxeTmFlaCiuuKysLfUgD.png"},{"name":"快哭了","img":"http://zos.alipayobjects.com/rmsportal/ckqavttaobgskHkqyGgq.png"},{"name":"对不起","img":"http://zos.alipayobjects.com/rmsportal/RBSoiDwKUlxLMjxIrGFo.png"},{"name":"邪恶","img":"http://zos.alipayobjects.com/rmsportal/IPFLJDAhPRcOsdErDDuD.png"},{"name":"傲慢","img":"http://zos.alipayobjects.com/rmsportal/cJtpLLRmKIDUYwcatUyb.png"},{"name":"安慰","img":"http://zos.alipayobjects.com/rmsportal/ZgzXJtifTdAetLMZyEnt.png"},{"name":"吓","img":"http://zos.alipayobjects.com/rmsportal/rFEePIrZNGDFZxeFycEh.png"},{"name":"口罩","img":"http://zos.alipayobjects.com/rmsportal/FUlRhotymKnjFUpQcxcH.png"},{"name":"害羞","img":"http://zos.alipayobjects.com/rmsportal/FzuYAQazaWcOSflxSwfz.png"},{"name":"思考","img":"http://zos.alipayobjects.com/rmsportal/DlRZQtaNeNhXrbrYYbDA.png"},{"name":"财迷","img":"http://zos.alipayobjects.com/rmsportal/BsqDYaPQXKLYiKJiLpmP.png"},{"name":"饥饿","img":"http://zos.alipayobjects.com/rmsportal/njkAErFQlstkkwPKhIQv.png"},{"name":"享受","img":"http://zos.alipayobjects.com/rmsportal/bdAwemhoFJAICnmEQbOi.png"},{"name":"天使","img":"http://zos.alipayobjects.com/rmsportal/YKCPgSilgrevVFxWCUUE.png"},{"name":"调皮","img":"http://zos.alipayobjects.com/rmsportal/EtvZFuvWWFgWRQlSQYlv.png"},{"name":"加油","img":"http://zos.alipayobjects.com/rmsportal/KMPMaIQwVsHgRmcniOLl.png"},{"name":"恭喜发财","img":"http://zos.alipayobjects.com/rmsportal/LLrenTkwKjfaYkuAZjNR.png"},{"name":"好主意","img":"http://zos.alipayobjects.com/rmsportal/vRmgSdXsJvPeBRdMYaXW.png"},{"name":"呼叫","img":"http://zos.alipayobjects.com/rmsportal/FmPHKOXOELMETSADHNZP.png"},{"name":"酷","img":"http://zos.alipayobjects.com/rmsportal/leQKNWeOKuawrXglOhDJ.png"},{"name":"发呆","img":"http://zos.alipayobjects.com/rmsportal/EVDkinwBjnEfwfJxCiPo.png"},{"name":"牛X","img":"http://zos.alipayobjects.com/rmsportal/yHZZFufgLqVOoeoMqbjx.png"},{"name":"老大","img":"http://zos.alipayobjects.com/rmsportal/PfbPLjjTFYacxasUUEAW.png"},{"name":"怀疑","img":"http://zos.alipayobjects.com/rmsportal/LKmNcwdYoFJuAIorZEoT.png"},{"name":"背","img":"http://zos.alipayobjects.com/rmsportal/pIcliCDowyzLoTnbUoWA.png"},{"name":"生病","img":"http://zos.alipayobjects.com/rmsportal/kqPVIqIVTtJgJySxHMes.png"},{"name":"没办法","img":"http://zos.alipayobjects.com/rmsportal/OFLYGCqNfiICITzJhxFY.png"},{"name":"拥抱","img":"http://zos.alipayobjects.com/rmsportal/KkJVlJiUgXDIqsiCStxA.png"},{"name":"闪电","img":"http://zos.alipayobjects.com/rmsportal/tCzmszHMiEWEoMDRlgTt.png"},{"name":"月亮","img":"http://zos.alipayobjects.com/rmsportal/ucfhvUfxlQJEOotyZbvO.png"},{"name":"太阳","img":"http://zos.alipayobjects.com/rmsportal/MANWPNnYeubfFmyqDPLL.png"},{"name":"强","img":"http://zos.alipayobjects.com/rmsportal/xMZgUDYflpsUpHJMumLM.png"},{"name":"弱","img":"http://zos.alipayobjects.com/rmsportal/kFnkqPwkCLOcWEICxUUj.png"},{"name":"握手","img":"http://zos.alipayobjects.com/rmsportal/dubWiUJcJryEVeiKzSuo.png"},{"name":"胜利","img":"http://zos.alipayobjects.com/rmsportal/gOdQBVcvDhpQThRLrNdA.png"},{"name":"抱拳","img":"http://zos.alipayobjects.com/rmsportal/kIwiEaPreKCLNMcbyYlC.png"},{"name":"勾引","img":"http://zos.alipayobjects.com/rmsportal/CTUpRxKdbqfOyOzERHbC.png"},{"name":"拳头","img":"http://zos.alipayobjects.com/rmsportal/DPtmqazqoVnNlGaeSUoD.png"},{"name":"差劲","img":"http://zos.alipayobjects.com/rmsportal/OUsFMCpeHUXedPPhxCsi.png"},{"name":"我爱你","img":"http://zos.alipayobjects.com/rmsportal/hEjDNQVOxsoaaVoSbDje.png"},{"name":"NO","img":"http://zos.alipayobjects.com/rmsportal/ppcTjerzglgNnAFBkylw.png"},{"name":"OK","img":"http://zos.alipayobjects.com/rmsportal/aaSedHrFPGomDduUUtHV.png"},{"name":"鼓掌","img":"http://zos.alipayobjects.com/rmsportal/ZNoMmHBjRDvSutRvEgGE.png"},{"name":"合十","img":"http://zos.alipayobjects.com/rmsportal/oOFmtinwhVZzzPZGHhEU.png"},{"name":"玫瑰","img":"http://zos.alipayobjects.com/rmsportal/UObiShuEMJAPUAvboZgx.png"},{"name":"凋谢","img":"http://zos.alipayobjects.com/rmsportal/fAJtbahsfUEOoQtcoCnP.png"},{"name":"嘴唇","img":"http://zos.alipayobjects.com/rmsportal/cqzSVUrKcBWPLQucUuTf.png"},{"name":"爱心","img":"http://zos.alipayobjects.com/rmsportal/NoAHykvUXzSUiOXOVsvz.png"},{"name":"心碎","img":"http://zos.alipayobjects.com/rmsportal/wlsBPbOhOtBhMKrHhQfy.png"},{"name":"红包","img":"http://zos.alipayobjects.com/rmsportal/RQuEvgHLzHZmRymlbRSU.png"},{"name":"菜刀","img":"http://zos.alipayobjects.com/rmsportal/ZjXlhiFnenkSQBkMmcMT.png"},{"name":"咖啡","img":"http://zos.alipayobjects.com/rmsportal/zcPdAViWJlXuDUuRdkHM.png"},{"name":"饭","img":"http://zos.alipayobjects.com/rmsportal/cetLAHMbSONSwQIDUwVH.png"},{"name":"猪头","img":"http://zos.alipayobjects.com/rmsportal/FsNoNJhdbNDsDLqfxewh.png"},{"name":"足球","img":"http://zos.alipayobjects.com/rmsportal/yaPcYigNgovIXSCBHxpz.png"},{"name":"便便","img":"http://zos.alipayobjects.com/rmsportal/EJbyBWlpCITUzyeCwMpT.png"},{"name":"礼物","img":"http://zos.alipayobjects.com/rmsportal/hbUQRzzKQibBhTpicCoP.png"},{"name":"钱","img":"http://zos.alipayobjects.com/rmsportal/ZzWXvXfaUFBntPHjmsZz.png"},{"name":"恶魔","img":"http://zos.alipayobjects.com/rmsportal/lBwrDtuvPenUFydKxDzG.png"},{"name":"蛋糕","img":"http://zos.alipayobjects.com/rmsportal/zpynVyEHlhUgvKrrnzBq.png"},{"name":"打屁股","img":"http://zos.alipayobjects.com/rmsportal/gJKtKKEtIRGshnNBhlXf.png"},{"name":"招财猫","img":"http://zos.alipayobjects.com/rmsportal/HfTVaHdnCCrjhOOTAHoY.png"}]

  如何将其使用Java遍历出来那个json对象中的name和img?

2.原因分析

  首先,整体是一个json数组;

  其次,每一个元素都是json对象。

3.解决方案

  导包:

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;  

  第一步:将这个字符串放入到Java中并当成字符串来识别。

  声明一个字符串并将值设为空;

String str = "";

  将上面的值拷贝至双引号""之间,Java会自动帮你完成转义。

String str = "[{\"name\":\"微微笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/TbDyUuhymEDMHWiKAqUw.png\"},{\"name\":\"羞羞\",\"img\":\"http://zos.alipayobjects.com/rmsportal/QqlNIwJLFrztbcePzojb.png\"},{\"name\":\"吐舌头\",\"img\":\"http://zos.alipayobjects.com/rmsportal/mphUsGFrBDfVixNLigpy.png\"},{\"name\":\"哈哈大笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/bKZHSElGKnVVEAjZsKEm.png\"},{\"name\":\"安慰一下\",\"img\":\"http://zos.alipayobjects.com/rmsportal/iUOoiEMFnCcOBpBYSbcA.png\"},{\"name\":\"抱抱\",\"img\":\"http://zos.alipayobjects.com/rmsportal/aJzJixNlsdWRPtCqlFgG.png\"},{\"name\":\"耶\",\"img\":\"http://zos.alipayobjects.com/rmsportal/DshwVWFCrJqXoAWCFYxd.png\"},{\"name\":\"你牛\",\"img\":\"http://zos.alipayobjects.com/rmsportal/VVkRWduhMRZUEayYsydn.png\"},{\"name\":\"亲一个\",\"img\":\"http://zos.alipayobjects.com/rmsportal/pFfAnQYxWTsaBaOrIiGy.png\"},{\"name\":\"花痴\",\"img\":\"http://zos.alipayobjects.com/rmsportal/OgOMiGBaLEsKVjmywQSY.png\"},{\"name\":\"算下账\",\"img\":\"http://zos.alipayobjects.com/rmsportal/gAnUTYnuVBhELZvgnQhC.png\"},{\"name\":\"拜拜\",\"img\":\"http://zos.alipayobjects.com/rmsportal/hmHqZNsDpotoUbOaPwoU.png\"},{\"name\":\"色情狂\",\"img\":\"http://zos.alipayobjects.com/rmsportal/jfCpZgEangcUhxtWNjBn.png\"},{\"name\":\"无聊发呆\",\"img\":\"http://zos.alipayobjects.com/rmsportal/GrVGDRymXemQzzBkcuoi.png\"},{\"name\":\"小样\",\"img\":\"http://zos.alipayobjects.com/rmsportal/etcvwaipQIrfWWPDizgE.png\"},{\"name\":\"摇头\",\"img\":\"http://zos.alipayobjects.com/rmsportal/OGirQyCBgWMjcdSNjfKu.png\"},{\"name\":\"傻傻笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/rDjBdQzqQimXkivksSvN.png\"},{\"name\":\"不会吧\",\"img\":\"http://zos.alipayobjects.com/rmsportal/JaYhdfsIQrjsTEqqPoiv.png\"},{\"name\":\"困了\",\"img\":\"http://zos.alipayobjects.com/rmsportal/emSaBGCQjqglinCAoOWQ.png\"},{\"name\":\"眼泪掉下来\",\"img\":\"http://zos.alipayobjects.com/rmsportal/YqhwlIJfOpAVFpDstsXe.png\"},{\"name\":\"痛哭\",\"img\":\"http://zos.alipayobjects.com/rmsportal/iRSIswAaEwrFgJjJnCrk.png\"},{\"name\":\"鄙视你\",\"img\":\"http://zos.alipayobjects.com/rmsportal/IpWUDFIYjrowojLtidKo.png\"},{\"name\":\"大怒\",\"img\":\"http://zos.alipayobjects.com/rmsportal/eWVMzvFpQnWXNqXVTpuh.png\"},{\"name\":\"学习雷锋\",\"img\":\"http://zos.alipayobjects.com/rmsportal/OLEdTsPLUuXymHzhaIAp.png\"},{\"name\":\"约架啊\",\"img\":\"http://zos.alipayobjects.com/rmsportal/TDHmPgepgvNacJuEQxbW.png\"},{\"name\":\"惊声尖叫\",\"img\":\"http://zos.alipayobjects.com/rmsportal/jRzlKZZmrHUPplhwzUif.png\"},{\"name\":\"成交\",\"img\":\"http://zos.alipayobjects.com/rmsportal/FiQetAvYpWNnlnljTMwi.png\"},{\"name\":\"拍手\",\"img\":\"http://zos.alipayobjects.com/rmsportal/NdlnyAZlyzwkYOmyKPET.png\"},{\"name\":\"愉快\",\"img\":\"http://zos.alipayobjects.com/rmsportal/fizHirPrEYbZylPXFfyf.png\"},{\"name\":\"撇嘴\",\"img\":\"http://zos.alipayobjects.com/rmsportal/YcfeFpumJriXrTsLyPGR.png\"},{\"name\":\"色\",\"img\":\"http://zos.alipayobjects.com/rmsportal/tIiReQQiOtcUCaudHJfn.png\"},{\"name\":\"傻笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/bljVgILMsFSBvdypFMfR.png\"},{\"name\":\"得意\",\"img\":\"http://zos.alipayobjects.com/rmsportal/BlfPFKcmCBxRDAoNTSzW.png\"},{\"name\":\"流泪\",\"img\":\"http://zos.alipayobjects.com/rmsportal/vHwkArAhUlwQSoEVGNbm.png\"},{\"name\":\"色眯眯\",\"img\":\"http://zos.alipayobjects.com/rmsportal/CDejqiJYJPCztsuefYyt.png\"},{\"name\":\"闭嘴\",\"img\":\"http://zos.alipayobjects.com/rmsportal/hayTisHQQBwHCxzOnLFi.png\"},{\"name\":\"可怜\",\"img\":\"http://zos.alipayobjects.com/rmsportal/WomzNePHtafzoBhSflBy.png\"},{\"name\":\"亲亲\",\"img\":\"http://zos.alipayobjects.com/rmsportal/MSIFcsNcthTkTGdcQFvZ.png\"},{\"name\":\"无聊\",\"img\":\"http://zos.alipayobjects.com/rmsportal/tTjSunKdTxsEYiLsMfKY.png\"},{\"name\":\"发怒\",\"img\":\"http://zos.alipayobjects.com/rmsportal/BHdbDLnkhQfJZXIssRMB.png\"},{\"name\":\"做鬼脸\",\"img\":\"http://zos.alipayobjects.com/rmsportal/EEdQAFozQudOURwLxmJT.png\"},{\"name\":\"呲牙\",\"img\":\"http://zos.alipayobjects.com/rmsportal/OptBofCVNBfMmqFiVOao.png\"},{\"name\":\"难过\",\"img\":\"http://zos.alipayobjects.com/rmsportal/RHJhmkZCovuNjWxaifJw.png\"},{\"name\":\"抢劫\",\"img\":\"http://zos.alipayobjects.com/rmsportal/QHZQcHHCYuLvLGienwXT.png\"},{\"name\":\"抠鼻\",\"img\":\"http://zos.alipayobjects.com/rmsportal/eZmlONTSMxKCKaXpFiyy.png\"},{\"name\":\"冷汗\",\"img\":\"http://zos.alipayobjects.com/rmsportal/YMkmgOUlhjTQhesBEtJp.png\"},{\"name\":\"阴险\",\"img\":\"http://zos.alipayobjects.com/rmsportal/iDCAEYKkqywAHGsetYlL.png\"},{\"name\":\"竖中指\",\"img\":\"http://zos.alipayobjects.com/rmsportal/hjGuxwUDEyTkjXUFRSQd.png\"},{\"name\":\"鄙视\",\"img\":\"http://zos.alipayobjects.com/rmsportal/XhDuTHhCfdHmAemrPTAu.png\"},{\"name\":\"抓狂\",\"img\":\"http://zos.alipayobjects.com/rmsportal/jfSiTeJEalHSWxuSbgqP.png\"},{\"name\":\"偷笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/euzSnRyBmrMciYzTjDyX.png\"},{\"name\":\"敲打\",\"img\":\"http://zos.alipayobjects.com/rmsportal/HyZJVaideowUoLeYQSpz.png\"},{\"name\":\"白眼\",\"img\":\"http://zos.alipayobjects.com/rmsportal/pXVjDURZUWEFDanBdAeN.png\"},{\"name\":\"吐血\",\"img\":\"http://zos.alipayobjects.com/rmsportal/PpjzXzOMeAnjMIhAYwGc.png\"},{\"name\":\"大笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/wCNEOMxiXaAuAJTkurNL.png\"},{\"name\":\"尴尬\",\"img\":\"http://zos.alipayobjects.com/rmsportal/OjQZbjiXxsRwQhYwweKa.png\"},{\"name\":\"困\",\"img\":\"http://zos.alipayobjects.com/rmsportal/IuRNVaBtnXJkJUiaUXNx.png\"},{\"name\":\"惊恐\",\"img\":\"http://zos.alipayobjects.com/rmsportal/BElZbmLJFfQTAfVcLiDN.png\"},{\"name\":\"流汗\",\"img\":\"http://zos.alipayobjects.com/rmsportal/nmaknEdnQbfpPvxFuRcZ.png\"},{\"name\":\"憨笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/mJYqVPZlCXjPbCESDTMw.png\"},{\"name\":\"休闲\",\"img\":\"http://zos.alipayobjects.com/rmsportal/tjyOfwKxDLOkodgBbAxj.png\"},{\"name\":\"大哭\",\"img\":\"http://zos.alipayobjects.com/rmsportal/MjypprGUjGScqJhCdoLO.png\"},{\"name\":\"奋斗\",\"img\":\"http://zos.alipayobjects.com/rmsportal/cbcsvsSpYzOWZqemmpWL.png\"},{\"name\":\"咒骂\",\"img\":\"http://zos.alipayobjects.com/rmsportal/kOMZoaGOwqeRBuQpTlMn.png\"},{\"name\":\"疑问\",\"img\":\"http://zos.alipayobjects.com/rmsportal/zxdZgsOZKShCTdRnOwyX.png\"},{\"name\":\"晕\",\"img\":\"http://zos.alipayobjects.com/rmsportal/WHTyMiMKqBOsuvgHHoUO.png\"},{\"name\":\"震惊\",\"img\":\"http://zos.alipayobjects.com/rmsportal/qnmbjuebnptBheOjIMqx.png\"},{\"name\":\"疯了\",\"img\":\"http://zos.alipayobjects.com/rmsportal/MLuTFzLImRSIHYQTFpfU.png\"},{\"name\":\"嘘\",\"img\":\"http://zos.alipayobjects.com/rmsportal/HyxOAnpMsbRXRZTWHJVo.png\"},{\"name\":\"露齿笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/MyFumBgjcXHewLaWzoeM.png\"},{\"name\":\"衰\",\"img\":\"http://zos.alipayobjects.com/rmsportal/KgRwkvdcyAuYPDkFEtSD.png\"},{\"name\":\"骷髅\",\"img\":\"http://zos.alipayobjects.com/rmsportal/wmrIsvpcRAArNQWQOzdn.png\"},{\"name\":\"骂人\",\"img\":\"http://zos.alipayobjects.com/rmsportal/aeluFDqOTuqlAJStPnwX.png\"},{\"name\":\"睡\",\"img\":\"http://zos.alipayobjects.com/rmsportal/OfCOALFWdAiakiYDkWVW.png\"},{\"name\":\"再见\",\"img\":\"http://zos.alipayobjects.com/rmsportal/ZycZvaDHdFIFlAovCxtS.png\"},{\"name\":\"笑哭\",\"img\":\"http://zos.alipayobjects.com/rmsportal/TyIBlJubSAAPCdRmQdGw.png\"},{\"name\":\"擦汗\",\"img\":\"http://zos.alipayobjects.com/rmsportal/IaHstwqoTVMRLGQAerDe.png\"},{\"name\":\"飞吻\",\"img\":\"http://zos.alipayobjects.com/rmsportal/rhTJPuWSFknKCPCXYRwW.png\"},{\"name\":\"爱慕\",\"img\":\"http://zos.alipayobjects.com/rmsportal/VnejNVxdfsxvNYnXktlQ.png\"},{\"name\":\"惊讶\",\"img\":\"http://zos.alipayobjects.com/rmsportal/MXfoCtzXulpZBXULFtCy.png\"},{\"name\":\"糗大了\",\"img\":\"http://zos.alipayobjects.com/rmsportal/RairwMrxBfbZVjhqlWNh.png\"},{\"name\":\"坏笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/kkeSAqIcPIojdFTWplKg.png\"},{\"name\":\"左哼哼\",\"img\":\"http://zos.alipayobjects.com/rmsportal/gLbJITQuiQOZCbVlKOfg.png\"},{\"name\":\"右哼哼\",\"img\":\"http://zos.alipayobjects.com/rmsportal/LbquIrqjViaajMvOWAio.png\"},{\"name\":\"哈欠\",\"img\":\"http://zos.alipayobjects.com/rmsportal/dDauYdGBkWHOTuIbrgPx.png\"},{\"name\":\"吐\",\"img\":\"http://zos.alipayobjects.com/rmsportal/CFMNDmAcxXjjVUoTWmcb.png\"},{\"name\":\"委屈\",\"img\":\"http://zos.alipayobjects.com/rmsportal/gcHkEsBDrRQVCtAsNRAv.png\"},{\"name\":\"微笑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/FxeTmFlaCiuuKysLfUgD.png\"},{\"name\":\"快哭了\",\"img\":\"http://zos.alipayobjects.com/rmsportal/ckqavttaobgskHkqyGgq.png\"},{\"name\":\"对不起\",\"img\":\"http://zos.alipayobjects.com/rmsportal/RBSoiDwKUlxLMjxIrGFo.png\"},{\"name\":\"邪恶\",\"img\":\"http://zos.alipayobjects.com/rmsportal/IPFLJDAhPRcOsdErDDuD.png\"},{\"name\":\"傲慢\",\"img\":\"http://zos.alipayobjects.com/rmsportal/cJtpLLRmKIDUYwcatUyb.png\"},{\"name\":\"安慰\",\"img\":\"http://zos.alipayobjects.com/rmsportal/ZgzXJtifTdAetLMZyEnt.png\"},{\"name\":\"吓\",\"img\":\"http://zos.alipayobjects.com/rmsportal/rFEePIrZNGDFZxeFycEh.png\"},{\"name\":\"口罩\",\"img\":\"http://zos.alipayobjects.com/rmsportal/FUlRhotymKnjFUpQcxcH.png\"},{\"name\":\"害羞\",\"img\":\"http://zos.alipayobjects.com/rmsportal/FzuYAQazaWcOSflxSwfz.png\"},{\"name\":\"思考\",\"img\":\"http://zos.alipayobjects.com/rmsportal/DlRZQtaNeNhXrbrYYbDA.png\"},{\"name\":\"财迷\",\"img\":\"http://zos.alipayobjects.com/rmsportal/BsqDYaPQXKLYiKJiLpmP.png\"},{\"name\":\"饥饿\",\"img\":\"http://zos.alipayobjects.com/rmsportal/njkAErFQlstkkwPKhIQv.png\"},{\"name\":\"享受\",\"img\":\"http://zos.alipayobjects.com/rmsportal/bdAwemhoFJAICnmEQbOi.png\"},{\"name\":\"天使\",\"img\":\"http://zos.alipayobjects.com/rmsportal/YKCPgSilgrevVFxWCUUE.png\"},{\"name\":\"调皮\",\"img\":\"http://zos.alipayobjects.com/rmsportal/EtvZFuvWWFgWRQlSQYlv.png\"},{\"name\":\"加油\",\"img\":\"http://zos.alipayobjects.com/rmsportal/KMPMaIQwVsHgRmcniOLl.png\"},{\"name\":\"恭喜发财\",\"img\":\"http://zos.alipayobjects.com/rmsportal/LLrenTkwKjfaYkuAZjNR.png\"},{\"name\":\"好主意\",\"img\":\"http://zos.alipayobjects.com/rmsportal/vRmgSdXsJvPeBRdMYaXW.png\"},{\"name\":\"呼叫\",\"img\":\"http://zos.alipayobjects.com/rmsportal/FmPHKOXOELMETSADHNZP.png\"},{\"name\":\"酷\",\"img\":\"http://zos.alipayobjects.com/rmsportal/leQKNWeOKuawrXglOhDJ.png\"},{\"name\":\"发呆\",\"img\":\"http://zos.alipayobjects.com/rmsportal/EVDkinwBjnEfwfJxCiPo.png\"},{\"name\":\"牛X\",\"img\":\"http://zos.alipayobjects.com/rmsportal/yHZZFufgLqVOoeoMqbjx.png\"},{\"name\":\"老大\",\"img\":\"http://zos.alipayobjects.com/rmsportal/PfbPLjjTFYacxasUUEAW.png\"},{\"name\":\"怀疑\",\"img\":\"http://zos.alipayobjects.com/rmsportal/LKmNcwdYoFJuAIorZEoT.png\"},{\"name\":\"背\",\"img\":\"http://zos.alipayobjects.com/rmsportal/pIcliCDowyzLoTnbUoWA.png\"},{\"name\":\"生病\",\"img\":\"http://zos.alipayobjects.com/rmsportal/kqPVIqIVTtJgJySxHMes.png\"},{\"name\":\"没办法\",\"img\":\"http://zos.alipayobjects.com/rmsportal/OFLYGCqNfiICITzJhxFY.png\"},{\"name\":\"拥抱\",\"img\":\"http://zos.alipayobjects.com/rmsportal/KkJVlJiUgXDIqsiCStxA.png\"},{\"name\":\"闪电\",\"img\":\"http://zos.alipayobjects.com/rmsportal/tCzmszHMiEWEoMDRlgTt.png\"},{\"name\":\"月亮\",\"img\":\"http://zos.alipayobjects.com/rmsportal/ucfhvUfxlQJEOotyZbvO.png\"},{\"name\":\"太阳\",\"img\":\"http://zos.alipayobjects.com/rmsportal/MANWPNnYeubfFmyqDPLL.png\"},{\"name\":\"强\",\"img\":\"http://zos.alipayobjects.com/rmsportal/xMZgUDYflpsUpHJMumLM.png\"},{\"name\":\"弱\",\"img\":\"http://zos.alipayobjects.com/rmsportal/kFnkqPwkCLOcWEICxUUj.png\"},{\"name\":\"握手\",\"img\":\"http://zos.alipayobjects.com/rmsportal/dubWiUJcJryEVeiKzSuo.png\"},{\"name\":\"胜利\",\"img\":\"http://zos.alipayobjects.com/rmsportal/gOdQBVcvDhpQThRLrNdA.png\"},{\"name\":\"抱拳\",\"img\":\"http://zos.alipayobjects.com/rmsportal/kIwiEaPreKCLNMcbyYlC.png\"},{\"name\":\"勾引\",\"img\":\"http://zos.alipayobjects.com/rmsportal/CTUpRxKdbqfOyOzERHbC.png\"},{\"name\":\"拳头\",\"img\":\"http://zos.alipayobjects.com/rmsportal/DPtmqazqoVnNlGaeSUoD.png\"},{\"name\":\"差劲\",\"img\":\"http://zos.alipayobjects.com/rmsportal/OUsFMCpeHUXedPPhxCsi.png\"},{\"name\":\"我爱你\",\"img\":\"http://zos.alipayobjects.com/rmsportal/hEjDNQVOxsoaaVoSbDje.png\"},{\"name\":\"NO\",\"img\":\"http://zos.alipayobjects.com/rmsportal/ppcTjerzglgNnAFBkylw.png\"},{\"name\":\"OK\",\"img\":\"http://zos.alipayobjects.com/rmsportal/aaSedHrFPGomDduUUtHV.png\"},{\"name\":\"鼓掌\",\"img\":\"http://zos.alipayobjects.com/rmsportal/ZNoMmHBjRDvSutRvEgGE.png\"},{\"name\":\"合十\",\"img\":\"http://zos.alipayobjects.com/rmsportal/oOFmtinwhVZzzPZGHhEU.png\"},{\"name\":\"玫瑰\",\"img\":\"http://zos.alipayobjects.com/rmsportal/UObiShuEMJAPUAvboZgx.png\"},{\"name\":\"凋谢\",\"img\":\"http://zos.alipayobjects.com/rmsportal/fAJtbahsfUEOoQtcoCnP.png\"},{\"name\":\"嘴唇\",\"img\":\"http://zos.alipayobjects.com/rmsportal/cqzSVUrKcBWPLQucUuTf.png\"},{\"name\":\"爱心\",\"img\":\"http://zos.alipayobjects.com/rmsportal/NoAHykvUXzSUiOXOVsvz.png\"},{\"name\":\"心碎\",\"img\":\"http://zos.alipayobjects.com/rmsportal/wlsBPbOhOtBhMKrHhQfy.png\"},{\"name\":\"红包\",\"img\":\"http://zos.alipayobjects.com/rmsportal/RQuEvgHLzHZmRymlbRSU.png\"},{\"name\":\"菜刀\",\"img\":\"http://zos.alipayobjects.com/rmsportal/ZjXlhiFnenkSQBkMmcMT.png\"},{\"name\":\"咖啡\",\"img\":\"http://zos.alipayobjects.com/rmsportal/zcPdAViWJlXuDUuRdkHM.png\"},{\"name\":\"饭\",\"img\":\"http://zos.alipayobjects.com/rmsportal/cetLAHMbSONSwQIDUwVH.png\"},{\"name\":\"猪头\",\"img\":\"http://zos.alipayobjects.com/rmsportal/FsNoNJhdbNDsDLqfxewh.png\"},{\"name\":\"足球\",\"img\":\"http://zos.alipayobjects.com/rmsportal/yaPcYigNgovIXSCBHxpz.png\"},{\"name\":\"便便\",\"img\":\"http://zos.alipayobjects.com/rmsportal/EJbyBWlpCITUzyeCwMpT.png\"},{\"name\":\"礼物\",\"img\":\"http://zos.alipayobjects.com/rmsportal/hbUQRzzKQibBhTpicCoP.png\"},{\"name\":\"钱\",\"img\":\"http://zos.alipayobjects.com/rmsportal/ZzWXvXfaUFBntPHjmsZz.png\"},{\"name\":\"恶魔\",\"img\":\"http://zos.alipayobjects.com/rmsportal/lBwrDtuvPenUFydKxDzG.png\"},{\"name\":\"蛋糕\",\"img\":\"http://zos.alipayobjects.com/rmsportal/zpynVyEHlhUgvKrrnzBq.png\"},{\"name\":\"打屁股\",\"img\":\"http://zos.alipayobjects.com/rmsportal/gJKtKKEtIRGshnNBhlXf.png\"},{\"name\":\"招财猫\",\"img\":\"http://zos.alipayobjects.com/rmsportal/HfTVaHdnCCrjhOOTAHoY.png\"}]";

  第二步:转换成JSON数组

JSONArray ja = JSONArray.fromObject(str);

  第三步:

  错误方式:直接遍历JSONArray

for (Object obj : ja) {
JSONObject jo = obj;
}

  你会发现无法将JSONArray中的元素强转成JSONObject,

  正确方式:将JSON数组转换成List并指定元素的格式

List<JSONObject> jsonList = JSONArray.toList(ja, new JSONObject(), new JsonConfig());

  第四步:遍历List

for (JSONObject jo : jsonList) {
System.out.println(jo.get("name") + "," + jo.get("img"));
}

4.效果展示

java 如何对由json对象构成的数组形式的字符串进行遍历?

写在最后

  哪位大佬如若发现文章存在纰漏之处或需要补充更多内容,欢迎留言!!!

相关推荐: