Here I have a code with json parsing, I need what json would parse from the server. How to do it?
package my.home.page; import android.app.*; import android.os.*; import org.json.*; import android.widget.*; import android.widget.AdapterView.*; import android.content.*; import android.net.*; import android.view.*; import android.util.*; import my.home.page.R; public class MainActivity extends Activity { String[] links, names; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView list = (ListView) findViewById(R.id.list); String json = "[{\"id\":1,\"link\":\"http://www.vk.com\",\"name\":\"VK\"}, {\"id\":1,\"link\":\"http://www.google.com\",\"name\":\"Google\"},{\"id\":1,\"link\":\"http://www.yandex.ru\",\"name\":\"Yandex\"}]"; try{ JSONArray array = new JSONArray(json); int size = array.length(); links = new String[size]; names = new String[size]; for(int n = 0; n < size; n++) { JSONObject obj = array.getJSONObject(n); links[n] = obj.getString("link"); names[n] = obj.getString("name"); } } catch (JSONException e){ Log.d("$", e.toString()); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names); list.setAdapter(adapter); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(links[position])); startActivity(i); } }); } }