-1
我遇到了一個我無法解決的問題。我希望你能更好地理解我。 我的代碼 GuideFragment.java在JSON包中打開對象
package ru.yktdevelopers.childrensofasia;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import ru.yktdevelopers.childrensofasia.Download_data.download_complete;
public class GuideFragment extends Fragment implements download_complete {
public ListView list;
public ArrayList<Countries> countries = new ArrayList<Countries>();
public ListAdapter adapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.guide_fragment, null);
list = (ListView) v.findViewById(R.id.list_guide);
adapter = new ListAdapter(this);
list.setAdapter(adapter);
Download_data download_data = new Download_data((download_complete) this);
download_data.download_data_from_link("http://9142218380.myjino.ru/testfile.json");
return v;
}
public void get_data(String data)
{
try {
JSONArray data_array=new JSONArray(data);
for (int i = 0 ; i < data_array.length() ; i++)
{
JSONObject obj=new JSONObject(data_array.get(i).toString());
Countries add=new Countries();
add.name = obj.getString("country");
add.code = obj.getString("code");
countries.add(add);
}
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
}
}
public class Countries {
String name;
String code;
}
}
的問題是: 如何使讓她能夠名爲「測試」打開對象。位於與http://9142218380.myjino.ru/testfile.json
[進入JSON在線編輯器(HTTP後:?//www.jsoneditoronline.org/ ID = fd603f56abb165b7d2fab65be6fbd821) –