从 Json 获取数据
To obtain data from Json
我想从以下Json获取countryId,countryName详情(请参考截图:http://i.imgur.com/DDs9rGT.png)
这是我的代码:http://prntscr.com/76jbm4
这里:
ArrayList 公司名称 = new ArrayList();
AutoCompleteTextView country_editText;
此 AutoCompleteTextView 向用户显示国家名称列表,我想获取用户选择的国家/地区的 countryId。
问题是我无法传递由 countryId 和 countryName 组成的 AutoCompleteTextView 的列表。
创建模型class
class country{
private String countryName;
private String countryPhonecode;
private int countryId;
private String countryCode;
//getters and setters
}
List<Country> countryNameList=new ArrayList<Country>();
for(int i=0;i<yourArray;i++){
JSONObject json=array.getJSONObject(i);
country c=new country();
c.setcountryName(json.getString("countryName"));
//do same with all parameter
countryNameList.add(c);
}
and Now use indexOf to find id of the list like that.
list.get(position).getCountryId().
希望对你有所帮助
我想从以下Json获取countryId,countryName详情(请参考截图:http://i.imgur.com/DDs9rGT.png)
这是我的代码:http://prntscr.com/76jbm4 这里: ArrayList 公司名称 = new ArrayList(); AutoCompleteTextView country_editText; 此 AutoCompleteTextView 向用户显示国家名称列表,我想获取用户选择的国家/地区的 countryId。
问题是我无法传递由 countryId 和 countryName 组成的 AutoCompleteTextView 的列表。
创建模型class
class country{
private String countryName;
private String countryPhonecode;
private int countryId;
private String countryCode;
//getters and setters
}
List<Country> countryNameList=new ArrayList<Country>();
for(int i=0;i<yourArray;i++){
JSONObject json=array.getJSONObject(i);
country c=new country();
c.setcountryName(json.getString("countryName"));
//do same with all parameter
countryNameList.add(c);
}
and Now use indexOf to find id of the list like that.
list.get(position).getCountryId().
希望对你有所帮助