我的模型类如下
public class mf_menu_data {
private static String TAG = "mf_menu_data class";
private String business;
private String description;
private ArrayList<String> categories;
public String cats;
public String getBusiness(){
return business;
}
public String getDescription(){
return description;
}
public ArrayList<String> getCategories(){
return categories;
}
public mf_menu_data(String JSONin) {
try {
ArrayList<String> categories = new ArrayList<String>();
JSONArray my_menus = new JSONArray(JSONin);
for (int i = 0; i < my_menus.length(); i++) {
JSONObject my_menu = my_menus.getJSONObject(i);
business = my_menu.getString("m_business");
description = my_menu.getString("m_description");
Log.v(TAG, "m_business, m_description");
JSONArray my_categories = my_menu.getJSONArray("menu_cat_set");
for (int j = 0; j < my_categories.length(); j++) {
JSONObject my_category = my_categories.getJSONObject(j);
categories.add(my_category.getString("mc_menu"));
categories.add(my_category.getString("mc_category_elGR"));
categories.add(my_category.getString("mc_category_enUS"));
categories.add(my_category.getString("mc_category_deDE"));
categories.add(my_category.getString("mc_category_frFR"));
categories.add(my_category.getString("mc_category_itIT"));
categories.add(my_category.getString("mc_category_ruRU"));
categories.add(my_category.getString("mc_category_zhCN"));
Log.v(TAG, "mc_category");
}
cats = categories.toString();
}
}
catch (JSONException e) {
Log.v(TAG, e.getLocalizedMessage());
}
}
我的MainActivity功能的来源是这个
protected void onPostExecute(String result) {
mJSONData = new Helpers().CreateJSON(result);
mf_menu_data menu_data = new mf_menu_data(mJSONData);
String s = menu_data.getBusiness()+" "+
menu_data.getDescription()+" "+
menu_data.getCategories().toString();
Toast.makeText(getBaseContext(), s , Toast.LENGTH_LONG).show();
TextView textView = (TextView)findViewById(R.id.tv1);
textView.setText(mJSONData);
Log.d("onPostExecute","mJSONData");
}
}
menu_data.getCategories()。toString()返回null!如果我在我的模型类中使用String变量并执行类似的操作 public String s = this.getCategories()。toString 我可以看到我的数据......案例是我的Json反序列化器在我的模型类中有数据,但由于某些原因它在主要活动中消失了.....
有什么想法吗?