-1
Ich stieß auf ein Problem, das ich nicht lösen kann. Ich hoffe du verstehst mich besser. Mein Code GuideFragment.javaÖffnen Sie das Objekt in JSON-Paket
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;
}
}
Das Problem ist: Wie so zu machen, dass sie in der Lage waren, das Objekt zu öffnen mit dem Namen „Test“.
JSON-Datei befindet sich mit http://9142218380.myjino.ru/testfile.json
[zum JSON Online Editor] (http geben : //www.jsoneditoronline.org/? id = fd603f56abb165b7d2fab65be6fbd821) –