<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eyedbits &#187; Android</title>
	<atom:link href="http://www.eyedbits.com/?feed=rss2&#038;tag=android" rel="self" type="application/rss+xml" />
	<link>http://www.eyedbits.com</link>
	<description>links, tutorials and code fragments regarding computer graphics</description>
	<lastBuildDate>Sat, 23 Jun 2018 05:45:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>How to receive and parse a JSON array</title>
		<link>http://www.eyedbits.com/?p=145</link>
		<comments>http://www.eyedbits.com/?p=145#comments</comments>
		<pubDate>Wed, 18 Jul 2012 14:38:20 +0000</pubDate>
		<dc:creator><![CDATA[busk]]></dc:creator>
				<category><![CDATA[general coding]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://www.eyedbits.com/?p=145</guid>
		<description><![CDATA[Situation: You got some (client) application, that needs data from a mysql database. The application cannot connect to the database itself. It sends a HTTP GET/POST request to a webserver, that gets the data out of the mysql database and &#8230; <a href="http://www.eyedbits.com/?p=145">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong>Situation:</strong><br />
You got some (client) application, that needs data from a mysql database.<br />
The application cannot connect to the database itself. It sends a HTTP GET/POST request to a webserver, that gets the data out of the mysql database and packs it into a JSON Array. This JSON Array is sent back to the client.</p>
<p>The client receives the JSON Array and parses it.</p>
<p>This is the php code for the webserver (inspired from <a href="http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/8339-connect-android-mysql-database-tutorial.html" title="Basic 4 Android Forum" target="_blank"></a>)</p>
<div class="smallSourceCode">
<pre class="brush: java; title: ; notranslate">	
/**
 * download list of registered users from server at cmd.eyedbits.com
 * 
 * @return list of users
 */
static Vector&lt;String&gt; downloadUserList() {
  Log.i(TAG, String.format(&quot;Downloading UserList&quot;));
  
  String serverUrl = SERVER_URL + SERVER_URL_QUERYUSERLIST;

  //TODO: implement multiple tries with exponential backoff if server is not responding		
  DefaultHttpClient hc = new DefaultHttpClient();
  ResponseHandler &lt;String&gt; res = new BasicResponseHandler();
  HttpGet getMethod = new HttpGet(serverUrl);

  Vector&lt;String&gt; retVector = new Vector&lt;String&gt;(); 
  try {
    String response = hc.execute(getMethod, res);
    Log.i(TAG, &quot;Http response: &quot; + response);
    // todo check if successfull and not error
    
    // parse string
    try {
      JSONArray jsonArray = new JSONArray(response);
      for (int i = 0; i &lt; jsonArray.length(); ++i) {
        JSONObject row = jsonArray.getJSONObject(i);
        String userName = row.getString(&quot;UserName&quot;);
        retVector.add(userName);
      }
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    
  } catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  
  return retVector;
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.eyedbits.com/?feed=rss2&#038;p=145</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
