Today i will explain how to parse JSON (Java Script Object Notation) in android application.
<?xml
version="1.0"
encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jsonparcer"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19"
/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name="com.example.jsonparcer.MainActivity"
android:label="@string/app_name"
>
<intent-filter>
<action
android:name="android.intent.action.MAIN"
/>
<category
android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:textSize="20dp"
android:layout_height="wrap_content"
android:text="@string/Employ"
/>
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_alignLeft="@+id/name"
android:layout_below="@+id/name"
android:layout_marginTop="23dp"
android:text="@string/Date"
/>
<TextView
android:id="@+id/hours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_below="@+id/date"
android:layout_marginTop="26dp"
android:text="@string/Time"
/>
<Button
android:id="@+id/data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="126dp"
android:text="@string/Data"
/>
</RelativeLayout>
strings.xml
<?xml
version="1.0"
encoding="utf-8"?>
<resources>
<string
name="app_name">Jsonparcer</string>
<string
name="action_settings">Settings</string>
<string
name="hello_world">Hello
world!</string>
<string
name="Employ">Ename
:</string>
<string
name="Date">Date
:</string>
<string
name="Time">WHours
:</string>
<string
name="Data">Data</string>
</resources>
work.txt
{
"TimeTable":{
"name":"Vamsi",
"date":"8-07-2014",
"time":"8hours"
}
}
Above codes are my source code for parsing json object using android . After running above code following screenshot will be generated
After button pressing it will retrieve data from work.txt next it will show using Textview on screen