In my android app, I have this JSON which looks like this :
{ "first_name": "ankit",
"last_name": "anurag",
"mobile": "8105580517",
"interest_input": [13, 14],
"user_cards": [
[17, "DBS NUS Alumni Platinum Card "],
[19, "DBS NUS Debit Card "]
],
"email": "ankit_anurag@stragure.com"}
As you can see for the "user_cards" key the value is a 2 dimensional Array, with id & name. I want to get these both.
The code I have written for this is here :
JSONArray existingCards = o.getJSONArray("user_cards");
exCards = new String[existingCards.length()][2];//populate ur Array with blanks to avoid entrance of null values
//fill up the blanks to prevent null
for(int i = 0; i < existingCards.length(); i++){
exCards[i][0] = "";
exCards[i][1] = "";
}
//fill up the actual data
for(int i = 0; i < existingCards.length(); i++){
String k = exCards[开发者_Python百科i][0];
String l = exCards[i][1];
Log.v("exC", k+" "+l);
}
But I am not able to retrieve the data. Please Help
You have to initialize each of the "row" arrays first:
exCards[0] = new String[SIZE];
exCards[1] = new String[SIZE];
Yo can do it in the foor-loop
精彩评论