<?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>Latest-Tutorial &#187; Social Networking</title>
	<atom:link href="http://latest-tutorial.com/tag/social-networking/feed/" rel="self" type="application/rss+xml" />
	<link>http://latest-tutorial.com</link>
	<description>Best Tutorials for Beginners of Java,Android,JavaScript,Asp.net,Objective C,C-Sharp and many other topics.We have experts tutorial material against these topics.</description>
	<lastBuildDate>Wed, 12 Jun 2013 13:57:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Android and JSON</title>
		<link>http://latest-tutorial.com/2012/06/21/android-and-json/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-and-json</link>
		<comments>http://latest-tutorial.com/2012/06/21/android-and-json/#comments</comments>
		<pubDate>Thu, 21 Jun 2012 12:05:49 +0000</pubDate>
		<dc:creator>Zeeshan Akhter</dc:creator>
				<category><![CDATA[Android Tutorials]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Application programming interface]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Online Communities]]></category>
		<category><![CDATA[Social Networking]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://latest-tutorial.com/?p=2043</guid>
		<description><![CDATA[1.1. Android and JSON JSON is a very condense data exchange format. Android includes the json.org libraries which allow to work easily with JSON files. 1.2. JSON Example: Twitter Twitter is a great source for JSON. You can just call a URI and retrieve JSON. Here are some examples: Table 1. Twitter URIs URI Description http://twitter.com/statuses/user_timeline/vogella.json Get the timeline [...]]]></description>
				<content:encoded><![CDATA[<div class="page-restrict-output"><div style="padding-left:5px; padding-right:5px; padding-bottom:5px; padding-top:5px; margin-left:auto; margin-right:auto; ">
<script type="text/javascript"><!--
google_ad_client = "pub-1265735558479661";
google_ad_width = 468;
google_ad_height = 60;
google_color_border = "FFFFFF";
google_color_link = "E895CC";
google_color_text = "000000";
google_color_bg = "FFFFFF";
google_color_url = "0066CC";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p><a href="http://www.flickr.com/photos/44792728@N00/3762360637" target="_blank"><img class="zemanta-img-inserted zemanta-img-configured alignright" title="JSON Card -- Front" src="http://i0.wp.com/latest-tutorial.com/wp-content/uploads/2012/06/3762360637_6b851c9478_m.jpg?resize=240%2C128" alt="JSON Card -- Front" data-recalc-dims="1" /></a></p>
<h3>1.1. Android and <a class="zem_slink" title="JSON" href="http://json.org/" rel="homepage" target="_blank">JSON</a></h3>
<p><a href="http://www.vogella.com/articles/JSON/article.html" target="_top">JSON </a> is a very condense <a class="zem_slink" title="Data exchange" href="http://en.wikipedia.org/wiki/Data_exchange" rel="wikipedia" target="_blank">data exchange</a> format. <a href="http://www.vogella.com/articles/Android/article.html" target="_top"> Android</a> includes the json.org libraries which allow to work easily with JSON files.</p>
<div>
<div>
<div>
<div>
<h3><a name="androidjson_twitter"></a>1.2. JSON Example: Twitter</h3>
</div>
</div>
</div>
<p><a href="http://twitter.com/vogella" target="_top"> Twitter </a> is a great source for JSON. You can just call a URI and retrieve JSON. Here are some examples:</p>
<div><a name="d1153e83"></a><strong>Table 1. Twitter <a class="zem_slink" title="Uniform Resource Identifier" href="http://en.wikipedia.org/wiki/Uniform_Resource_Identifier" rel="wikipedia" target="_blank">URIs</a></strong></p>
<div>
<table summary="Twitter URIs" border="1">
<colgroup>
<col align="left" />
<col align="left" /> </colgroup>
<thead>
<tr>
<th align="left">URI</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">http://twitter.com/statuses/<a class="zem_slink" title="User (computing)" href="http://en.wikipedia.org/wiki/User_%28computing%29" rel="wikipedia" target="_blank">user</a>_timeline/vogella.json</td>
<td align="left">Get the timeline of user vogella.</td>
</tr>
<tr>
<td align="left">http://search.twitter.com/search.json?q=android</td>
<td align="left">Search for the term &#8220;android&#8221; on Twitter.</td>
</tr>
<tr>
<td align="left">http://twitter.com/users/show/vogella.json</td>
<td align="left">Returns the user data of user vogella.</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>&nbsp;</p>
<p>Please note that some URIs return a JSONObject object while others return a JSONArray.</p>
</div>
<div>
<div>
<div>
<div>
<h2><a name="androidjson_read"></a>2. Reading JSON</h2>
</div>
</div>
</div>
<p>Create a new <a href="http://www.vogella.com/articles/Android/article.html" target="_top"> Android</a> project &#8220;de.vogella.android.twitter.json&#8221; with the package &#8220;de.vogella.android.twitter.json&#8221; and the activity &#8220;ParseJSON&#8221;.</p>
<p>Create the following coding for the activity. This will download the twitter feed for the user <a href="http://www.vogella.com/articles/AndroidJSON/vogella" target="_top">http://twitter.com/vogella </a> and write the number of entries and the <a class="zem_slink" title="Text messaging" href="http://en.wikipedia.org/wiki/Text_messaging" rel="wikipedia" target="_blank">text messages</a> to the Android log file.</p>
<p>&nbsp;</p>
<pre>package de.vogella.android.twitter.json;

<a class="zem_slink" title="Import" href="http://en.wikipedia.org/wiki/Import" rel="wikipedia" target="_blank">import</a> java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class ParseJSON extends Activity {</pre>
<div>/** Called when the activity is first created. */</div>
<pre>	<em><a class="zem_slink" title="Annotation" href="http://en.wikipedia.org/wiki/Annotation" rel="wikipedia" target="_blank">@Override</a></em>
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		String readTwitterFeed = readTwitterFeed();
		try {
			JSONArray jsonArray = new JSONArray(readTwitterFeed);
			Log.i(ParseJSON.class.getName(),
					"Number of entries " + jsonArray.length());
			for (int i = 0; i &lt; jsonArray.length(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				Log.i(ParseJSON.class.getName(), jsonObject.getString("text"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String readTwitterFeed() {
		StringBuilder builder = new StringBuilder();
		HttpClient client = new DefaultHttpClient();
		HttpGet httpGet = new HttpGet("http://twitter.com/statuses/user_timeline/vogella.json");
		try {
			HttpResponse response = client.execute(httpGet);
			StatusLine statusLine = response.getStatusLine();
			int statusCode = statusLine.getStatusCode();
			if (statusCode == 200) {
				HttpEntity entity = response.getEntity();
				InputStream content = entity.getContent();
				BufferedReader reader = new BufferedReader(new InputStreamReader(content));
				String line;
				while ((line = reader.readLine()) != null) {
					builder.append(line);
				}
			} else {
				Log.e(ParseJSON.class.toString(), "Failed to download file");
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return builder.toString();
	}
}</pre>
<p>&nbsp;</p>
<p>To run this example assign the uses-permission to your <code>AndroidManifest.xml</code> for &#8220;android.permission.INTERNET&#8221;.</p>
</div>
<div>
<div>
<div>
<div>
<h2><a name="androidjson_write"></a>3. Write JSON</h2>
</div>
</div>
</div>
<p>Writing JSON is very simple. Just create the JSONObject or JSONArray and use the toString() method.</p>
<p>&nbsp;</p>
<pre>				
public void writeJSON() {
	JSONObject object = new JSONObject();
	try {
		object.put("name", "Jack Hack");
		object.put("score", new <a class="zem_slink" title="Integer (computer science)" href="http://en.wikipedia.org/wiki/Integer_%28computer_science%29" rel="wikipedia" target="_blank">Integer</a>(200));
		object.put("current", new Double(152.32));
		object.put("nickname", "Hacker");
	} catch (JSONException e) {
		e.printStackTrace();
	}
	System.out.println(object);
}</pre>
<p>&nbsp;</p>
</div>
<div>
<div>
<div>
<div>
<h2><a name="thankyou"></a>4. Thank you</h2>
</div>
</div>
</div>
</div>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/?px"><img class="zemanta-pixie-img" style="float: right;" src="http://i2.wp.com/img.zemanta.com/zemified_e.png" alt="Enhanced by Zemanta" data-recalc-dims="1" /></a></div>
<center><script type="text/javascript"><!--
google_ad_client = "pub-1265735558479661";
google_ad_width = 468;
google_ad_height = 60;
google_color_border = "FFFFFF";
google_color_link = "E895CC";
google_color_text = "000000";
google_color_bg = "FFFFFF";
google_color_url = "0066CC";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center>
</div>]]></content:encoded>
			<wfw:commentRss>http://latest-tutorial.com/2012/06/21/android-and-json/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
