json轉(zhuǎn)化為數(shù)組 如何從jsonarray中取數(shù)據(jù)?
如何從jsonarray中取數(shù)據(jù)?我們需要編寫一個方法將JSON數(shù)據(jù)轉(zhuǎn)換成列表集合數(shù)據(jù),public staticlistjson tobean(字符串?dāng)?shù)據(jù),對象bean){listlist=newa
如何從jsonarray中取數(shù)據(jù)?
我們需要編寫一個方法將JSON數(shù)據(jù)轉(zhuǎn)換成列表集合數(shù)據(jù),public staticlistjson tobean(字符串?dāng)?shù)據(jù),對象bean){listlist=newarraylist()嘗試{jsonarraraytry{array=newjsonarray(data)for(inti=0I)<array.length長度()i){ObjecttoBean=getBean(bean)jsonobjecttob=newJSONObject()ob=(JSONObject)數(shù)組.get(i) toBean=jsonStrToBean(ob,toBean)列表.添加(toBean)}returnlist}catch(JSONExceptione){嘗試{Objectobj=nullJSONObjectjsonObj=newJSONObject(data)ObjecttoBean=getBean(bean)toBean=jsonStrToBean(jsonObj,toBean)列表.添加(toBean)returnlist}捕獲(JSONExceptione1){日志錯誤(“Er rorcovertStringtoJSONObject”,e)e1.printStackTrace()}e.printStackTrace()日志錯誤(“errorcoverstringtojsonarray“,e)}捕獲(securityexceptione){e.printstacktrace()}returnist},然后取出列表集數(shù)據(jù)中的值。應(yīng)該沒問題。