如何调用Android中的JSON对象对象、Android、JSON

由网友(紳士的熱吻)分享简介:我是新来的android开发。我有以下的Andr​​oid code调用JSON I am new to the android development. i am having the following android code to call the json try {JSONObject jsonObj...

我是新来的android开发。我有以下的Andr​​oid code调用JSON

I am new to the android development. i am having the following android code to call the json

  try {

        JSONObject jsonObject = new JSONObject(result);
        //JSONObject object = jsonObject.getJSONObject("CUSTOMER_ID");
        JSONArray jArray = new JSONArray(CUSTOMER_ID);
        returnUsername1 = jArray.getInt("CUSTOMER_ID");
        Toast.makeText(getApplicationContext(), ""+returnUsername1,Toast.LENGTH_LONG).show();
        for (int i = 0; i < jArray.length(); i++) {
 }

我的JSON格式如 [{0:1,CUSTOMER_ID:1}]]。

我是指一些JSON格式应该像 [{0:1,SNO:1}] 我可以理解this.But矿是从该不同

i refer some json format it should like [{"0":"1","sno":"1"}] i can understand this.But mine is different from this.

怎么能叫使用上述code.anyone可以提出一个解决方案CUSTOMER_ID。

how can i call the customer_id using the above code.anyone can suggest a solution.

推荐答案

你有什么是JSON数组

What you have is a Json Array

JSONArray jsonarray = new JSONArray(result); // result is a Array

[重presents JSON数组节点

[ represents json array node

{重presents JSON对象节点

{ represents json object node

您JSON。你需要一个JSON数组两次?

Your Json. Do you need a Json array twice?

  [ // array
    [ //array
        { // object
            "0": "1",  
            "CUSTOMER_ID": "1"
        }
    ]
   ]

解析

JSONArray jsonArray = new JSONArray(result);
JSONArray ja= (JSONArray) jsonArray.get(0);
JSONObject jb = (JSONObject) ja.get(0);
String firstvalue = jb.getString("0");
String secondvalue = jb.getString("CUSTOMER_ID");
Log.i("first value is",firstvalue);
Log.i("second value is",secondvalue);

LogCat中

LogCat

 07-22 14:37:02.990: I/first value is(6041): 1
 07-22 14:37:03.048: I/second value is(6041): 1
阅读全文

相关推荐

最新文章