JsonActivity.java
package com.gusfree.json;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class JsonActivity extends Activity {

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TextView textView= new TextView(this);
        //Object : {string:value,string:value,string:value...}
        String test1="{title:음식점,price:2000,location:강남}";
        String content="";
        try {
        	JSONObject jsonObject = new JSONObject(test1);
        	String title =jsonObject.getString("title");
        	String price =jsonObject.getString("price");
        	String location =jsonObject.getString("location");
        	content="title: "+title+" price: "+price+" locaction: "+location;
        
        } catch (JSONException e) {
			e.printStackTrace();
		}
        textView.setText(content);
        setContentView(textView);
        
	}
}
/* <Data>
 * 	  <title>음식점 </title>
 * 	  <price>2000 </price>
 * 	  <location>강남 </location>
 * </Data>
 * 
 * 
 * {"음식점",2000,강남} //Json 방식 Mobile
 * */
 








package com.gusfree.json;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class JsonActivity extends Activity {
 
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TextView textView= new TextView(this);
        //Object : {string:value,string:value,string:value...}
        String test1="{title:음식점,price:2000,location:강남}";
        String content="";
        try {
        	JSONObject jsonObject = new JSONObject(test1);
        	String title =jsonObject.getString("title");
        	String price =jsonObject.getString("price");
        	String location =jsonObject.getString("location");
        	content="title: "+title+" price: "+price+" locaction: "+location;
        
        	//JSONArray 따옴표 안에 따옴표를 표현하고 싶을 때
        	//\n
        	
        	String test2="[ \"목요일 \",\"금요일 \" ]";
        	JSONArray jasonArray =new JSONArray(test2);
        	Object first = jasonArray.get(0);
        	Object second = jasonArray.get(1);
        	content += "\n" +first.toString() + "\n" +second.toString();
        	
        } catch (JSONException e) {
			e.printStackTrace();
		}
        textView.setText(content);
        setContentView(textView);
        
	}
}
/* <Data>
 * 	  <title>음식점 </title>
 * 	  <price>2000 </price>
 * 	  <location>강남 </location>
 * </Data>
 * 
 * 
 * {"음식점",2000,강남} //Json 방식 Mobile
 * */
 



+ Recent posts