當前位置:首頁 » 安卓系統 » android數組解析

android數組解析

發布時間: 2022-08-03 05:42:21

A. android,想要解析下面的json數據,將id,name,weight分別取出放在不同的數組中 ,怎麼操作。求大神賜教

我的建議是用架包去解析。eg:compile 'com.alibaba:fastjson:1.2.17'

  1. 建bean包。裡麵包含City.java和Category.java.

  2. City.java中private in id;private String name;private in weight;set()和get();

  3. Category.java中private int datasCount;private ArrayList<City> datas; set()和get();

  4. Category category=JSON.parseObject(result, BatchBase.class);
    mList = category.getDatas();

  5. ArrayList mId = new ArrayList<Integer>();

    for(Integer m:mList){

    mId.add(mList.getId())

    }

  6. 其他兩個相同。

    注意:

    具體的細節寫法,我沒寫,所以麻煩你自己微調了。

B. android 解析 json 字元串數組問題

請求到數據後寫一個剖析器將數據用實體解析;

C. Android 該如何解析json數組裡面的數組

[]就是JSONArray,{}就是JSONObject
JSONObject json = new JSONObject("{xxx}");
json.getJsonArray("data").getJSONObject(0).getJsonArray("task_photo");

D. android解析這樣的json數組

我做了一個代碼如下:

{

ListViewlistview;

@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview=(ListView)findViewById(R.id.listview);
Stringtemp="[{"aa":"1","bb":"2"},{"aa":"3","bb":"4"},{"aa":"5","bb":"6"}]";
List<Map<String,Object>>data=getList(temp);
SimpleAdapteradapter=newSimpleAdapter(this,data,R.layout.item,newString[]{"aa","bb"},newint[]{R.id.aa,R.id.bb});
listview.setAdapter(adapter);
}

publicMap<String,Object>getMap(StringjsonString){
JSONObjectjsonObject;
try{
jsonObject=newJSONObject(jsonString);
@SuppressWarnings("unchecked")
Iterator<String>keyIter=jsonObject.keys();
Stringkey;
Objectvalue;
Map<String,Object>valueMap=newHashMap<String,Object>();
while(keyIter.hasNext()){
key=(String)keyIter.next();
value=jsonObject.get(key);
valueMap.put(key,value);
}
returnvalueMap;
}catch(JSONExceptione){
e.printStackTrace();
}
returnnull;
}

publicList<Map<String,Object>>getList(StringjsonString){
List<Map<String,Object>>list=null;
try{
JSONArrayjsonArray=newJSONArray(jsonString);
JSONObjectjsonObject;
list=newArrayList<Map<String,Object>>();
for(inti=0;i<jsonArray.length();i++){
jsonObject=jsonArray.getJSONObject(i);
list.add(getMap(jsonObject.toString()));
}
}catch(Exceptione){
e.printStackTrace();
}
returnlist;
}
}

E. android如何從網頁中獲取一個json數組並解析出來,顯示在textview裡面

1,先要建立一個線程獲取json數據
2接著解析json數據
3,設置textview
例如:json數據,strjson= {"key": ["a","b"]}
JSONObject object = new JSONObject (strjson)
JSONArray arr= object.getJSONArray("key") ;
String text=arr.getString(0);

F. android怎麼解析php返回的多維JSON數組格式

首先貼一段示例代碼:
<?php
include "con_db.php";//連接資料庫
$sql="select * from note order by note_date desc limit ".($index*10).",10"; //sql語句
$result=mysql_query($sql);//獲得結果
$note;$i=0; //初始化變數
while($infor=mysql_fetch_array($result))
{
//把結果放到一個一維數組里
$note["id"]=$infor['note_id'];
$note["content"]=$infor['note_content'];
$note["date"]=$infor['note_date'];
$note["username"]=$infor['username'];
//放到二維數組里
$notes[$i++]=$note;
}
echo json_encode($notes );
?>

輸出結果:
[{"id":"12","content":"u662f","date":"2014-05-24 09:31:52","username":"u532f"},
{"id":"31","content":"u642f","date":"2014-05-24 09:31:49","username":"u322f"},
{"id":"70","content":"u692f","date":"2014-05-24 09:31:48","username":"u132f"}]

你會發現應該輸出的漢字變成了unicode字元集.
這時我們就要用到urlencode的方法,把漢字用urlencode方法編碼,轉化為json之後再用urldecode解碼.看如下例子:
<?php
$h =urlencode("開心");
echo $h;
$x =urldecode($h);
echo $x;
?>

輸出結果:
%BF%AA%D0%C4開心

這樣通過中間過程的編碼和解碼,轉化成json的過程便不會自動把漢字變成Unicode字元集了.所以最後的方法為:
<?php
while($infor=mysql_fetch_array($re))
{
$note["id"]=$infor['note_id'];//數字不需要編碼
$note["content"]=urlencode($infor['note_content']);//漢字需要編碼
$note["date"]=$infor['note_date'];
$note["username"]=urlencode($infor['username']);
$notes[$i++]=$note;
}
echo urldecode(json_encode($notes ));//轉化成json之後再用urldecode解碼為漢字
?>

結果如下:
[{"id":"22","content":"文章","date":"2014-05-24 09:31:52","username":"王"},
{"id":"21","content":"內容","date":"2014-05-24 09:31:49","username":"李"},
{"id":"20","content":"可以","date":"2014-05-24 09:31:48","username":"馮"}]

參考資料:http://cuiqingcai.com/?p=27

G. android 解析json二維數組

按javascript的語法存取和解析。你例子中有明顯錯誤,js的數組和對象不分,php也不可能生成這樣的json。
按javascript的語法存取和解析。學會js,按js的規矩辦。

php下可用$a=json_decode()解碼這個串,然後按js的規矩
echo $a[0]['uname'];顯示York
echo $a[0]['tag']['2'];顯示北京
可以用foreach逐層遍歷,.和PHP的數組同樣的。

H. 1224android中網路請求對象數組的解析

一般都是使用xml或者JSON協議傳輸,如果是JSON協議,就用JSONArray來解析就行,或者用Gson來做解析 用ArrayList來接收就行了

I. android json數據數組中有數組怎麼解析

在計算機系統中,各種字母、數字元號的組合、語音、圖形、圖像等統稱為數據,數據經過加工後就成為信息。
在計算機科學中,數據是指所有能輸入到計算機並被計算機程序處理的符號的介質的總稱,是用於輸入電子計算機進行處理,具有一定意義的數字、字母、符號和模擬量等的通稱。是組成地理信息系統的最基本要素,種類很多

J. android怎樣解析Json並列序列的數組

[["北京市"],["上海市"],["合肥市","蕪湖市","蚌埠市"]] 這是一個JsonArray ,先獲取JsonArray對象,然後再次獲取獲取JsonArray對象:子JsonArray對象=父JsonArray對象.get(index值);最後,獲取子JsonArray對象裡面的數據,子JsonArray對象.get(index值);

熱點內容
編譯原理什麼內容 發布:2024-04-28 00:01:33 瀏覽:478
安卓手機怎麼登錄ipadid 發布:2024-04-27 23:52:25 瀏覽:671
瀏覽量和訪問次數 發布:2024-04-27 23:44:56 瀏覽:476
在linuxpython 發布:2024-04-27 22:38:57 瀏覽:316
機頂盒密碼是在哪裡 發布:2024-04-27 22:32:47 瀏覽:158
名圖買哪個配置值得買 發布:2024-04-27 22:32:36 瀏覽:878
比亞迪秦pro選哪個配置好 發布:2024-04-27 22:32:34 瀏覽:534
logn演算法 發布:2024-04-27 21:58:36 瀏覽:596
11選五的簡單演算法 發布:2024-04-27 21:46:14 瀏覽:71
ebay圖片上傳 發布:2024-04-27 21:31:50 瀏覽:587