android - Get web page content (with json array) -
i trying web page content (i have in page json array), , can not find way it, evry code found in google dont work , crash application..
i need help!
thanks!
take here:
https://code.google.com/p/android-query/
this library allows (can many things) take json specific url in simple way. know quite , never had problems.
i'll show example:
json on page
{ "account":{ "username":"nirbe" } }
myactivity.java
public class myactivity extends activity { private aquery aquery; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_activity); // first of all, create new aquery object aquery = new aquery(this); // ajax call aquery.ajax("http://www.nirberko.info/android/index.php", jsonobject.class, new ajaxcallback<jsonobject>() { @override public void callback(string url, jsonobject json, ajaxstatus status) { if (json != null) { try { // here receive json object, // use wish string username = json.getjsonobject("account").getstring("username"); // in case, can directly update view here aquery.id(r.id.tv_name).text(username); } catch (jsonexception e) { e.printstacktrace(); } } } }); } }
my_activity.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <textview android:id="@+id/tv_name" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </linearlayout>
Comments
Post a Comment