在我的Android应用程序中,我有这个看起来像这样的JSON:
{ "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"}
正如您在“user_cards”键中看到的那样,该值是一个二维数组,其中包含id&名称。 我想得到这两个。
我为此编写的代码在这里:
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[i][0];
String l = exCards[i][1];
Log.v("exC", k+" "+l);
}
但我无法检索数据。请帮忙
答案 0 :(得分:-1)
您必须首先初始化每个“行”数组:
exCards[0] = new String[SIZE];
exCards[1] = new String[SIZE];
哟可以在foor-loop中做到这一点