This is a regular Json object. Take it and parse it.
String json = "{\"id\":1,\"link\":\"http://www.vk.com\",\"name\":\"VK\"}"; JSONObject obj = new JSONObject(json); String url = obj.getString("link"); String name = obj.getString("name");
You now have a link and text for the button. Find the button. We put the program text and write the listener.
Button go = (Button) findViewById(R.id.button); go.setText(name); go.setOnClickListener(new OnClickListener() { @Override public void onClick(View v){ Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } });
Read this article. There everything about JSON painted.
UPD
About the list - everything is simple. So let's go. First, JSON the JSON array.
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\"}"; JSONArray array = new JSONArray(json); int size = array.length(); String[] links = new String[size]; String[] 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"); }
Everything, we have arrays with links and site names. Next we need to create a ListView in the markup.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ListView android:id="@+id/list" android:layout_height="wrap_content" android:layout_width="wrap_content"/> </LinearLayout>
Now create an adapter and fill the list with data.
ListView list = (ListView) findViewById(R.id.list); list.setLayoutManager(new LinearLayoutManager(this)); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, names); listView.setAdapter(adapter);
And the listener for the list.
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-1])); startActivity(i); } });
We use the position of the clicked item (list item) as an index for an array of links.
FULL CODE
MainActivity.java
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.*; 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<>(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); } }); } }
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="top"> <ListView android:id="@+id/list" android:layout_height="match_parent" android:layout_width="match_parent"/> </LinearLayout>
As I understand it, you don’t know the basic things in development, so I’ll give you some good learning sites.
StartAndroid
Alexander Klimov website
To learn, you only need to read blogs and practice a lot. Google It is most important. Everything you need is already there. We can only understand all this.
Oh yes, screenshot:

Happy coding!