Android json中的googleapi解析

Android json中的googleapi解析,android,ajax,json,Android,Ajax,Json,如何以JSON格式解析此URL " public类MainActivity扩展了ListActivity{ 私人语境; 专用静态字符串url=”https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=pixelloid&rsz=8"; 私有静态最终字符串标记\u VTYPE=“responseData”; 私有静态最终字符串标记_VCOLOR=“结果”; 专用静态最终字符串标记_FUEL=“GsearchResultClass”;

如何以JSON格式解析此URL

"

public类MainActivity扩展了ListActivity{
私人语境;
专用静态字符串url=”https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=pixelloid&rsz=8";
私有静态最终字符串标记\u VTYPE=“responseData”;
私有静态最终字符串标记_VCOLOR=“结果”;
专用静态最终字符串标记_FUEL=“GsearchResultClass”;
私有静态最终字符串标记_trade=“url”;
私有静态最终字符串标记_OPERATOR=“url”;
私有静态最终字符串标记_NAME=“NAME”;
私有静态最终字符串标记_POINTS=“experiencePoints”;
ArrayList jsonlist=新的ArrayList();
ListView lv;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
新建ProgressTask(MainActivity.this).execute();
}
私有类ProgressTask扩展了AsyncTask{
私人对话;
私人上市活动;
//私人列表消息;
公共进程任务(列表活动){
这个。活动=活动;
上下文=活动;
dialog=新建进度对话框(上下文);
}
/**“进度”对话框,向用户显示备份正在处理*/
/**应用程序上下文*/
私人语境;
受保护的void onPreExecute(){
this.dialog.setMessage(“进度开始”);
this.dialog.show();
}
@凌驾
受保护的void onPostExecute(最终布尔值成功){
if(dialog.isShowing()){
dialog.dismise();
}
ListAdapter=new SimpleAdapter(上下文,jsonlist,
R.layout.list_项,新字符串[]{TAG_VTYPE,TAG_VCOLOR,
TAG_FUEL,TAG_TREAD},新int[]{
R.id.车辆类型,R.id.车辆颜色,R.id.燃油,
R.id.treadType});
setListAdapter(适配器);
//选择单个ListView项
lv=getListView();
}
受保护的布尔doInBackground(最终字符串…args){
JSONParser jParser=新的JSONParser();
//从URL获取JSON字符串
JSONArray json=jParser.getJSONFromUrl(url);
if(json==null){
//通知用户
Log.e(“==>”,“下载文件失败”);
} 
否则{
for(int i=0;ivalue
地图放置(标签_VTYPE,VTYPE);
地图放置(TAG_VCOLOR,VCOLOR);
地图放置(标记燃料、vfuel);
地图放置(标记踏板,vtread);
jsonlist.add(map);
}捕获(JSONException e){
//TODO自动生成的捕捉块
e、 printStackTrace();
Log.e(“==>”,“iyogbr;g;ui”);
}
}
}
返回null;
}
}
}
我正在分析这些数据:

{"responseData":{"results":[{"content":"<b>Pixelloid<\/b> Studios Visual Effects, 3D Animation Production and Training Institute.","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid - Visual Effects, 3D Animation - Production and Training","title":"<b>Pixelloid<\/b> - Visual Effects, 3D Animation - Production and Training","cacheUrl":"http:\/\/www.google.com\/search?q=cache:Uq3_USWdbwIJ:www.pixelloid.com","unescapedUrl":"http:\/\/www.pixelloid.com\/","url":"http:\/\/www.pixelloid.com\/","visibleUrl":"www.pixelloid.com"},{"content":"Pixelloid Studios Visual Effects, 3D   Animation Production and Training <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Production and Training Institute - Pixelloid","title":"Production and Training Institute - <b>Pixelloid<\/b>","cacheUrl":"http:\/\/www.google.com\/search?q=cache:Pce2UIgSVDoJ:www.pixelloid.com","unescapedUrl":"http:\/\/www.pixelloid.com\/training\/","url":"http:\/\/www.pixelloid.com\/training\/","visibleUrl":"www.pixelloid.com"},{"content":"<b>Pixelloid<\/b> is an award winning 3D Animation &amp; Visual Effects Production and   Training Studio based in Hyderabad with branches in Bangalore, Visakhapatnam   <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid Studios - YouTube","title":"<b>Pixelloid<\/b> Studios - YouTube","cacheUrl":"http:\/\/www.google.com\/search?q=cache:wrfWBrpn45AJ:www.youtube.com","unescapedUrl":"http:\/\/www.youtube.com\/user\/pixelloid","url":"http:\/\/www.youtube.com\/user\/pixelloid","visibleUrl":"www.youtube.com"},{"content":"<b>Pixelloid<\/b>, Hyderabad, India. 5896 likes · 60 talking about this · 408 were here. We   help people tell their stories effectively. We do animation, visual effects for <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid - Hyderabad, India - Media\/News\/Publishing | Facebook","title":"<b>Pixelloid<\/b> - Hyderabad, India - Media\/News\/Publishing | Facebook","cacheUrl":"http:\/\/www.google.com\/search?q=cache:_m-PNJ9c3sgJ:www.facebook.com","unescapedUrl":"https:\/\/www.facebook.com\/Pixelloid","url":"https:\/\/www.facebook.com\/Pixelloid","visibleUrl":"www.facebook.com"},{"content":"Welcome to the company profile of <b>Pixelloid<\/b> Studios Private Limited on LinkedIn.   <b>Pixelloid<\/b> is an award winning Content Creation Company with an active <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid Studios Private Limited | LinkedIn","title":"<b>Pixelloid<\/b> Studios Private Limited | LinkedIn","cacheUrl":"http:\/\/www.google.com\/search?q=cache:vnyg3sUrGfgJ:www.linkedin.com","unescapedUrl":"http:\/\/www.linkedin.com\/company\/pixelloid-studios-private-limited","url":"http:\/\/www.linkedin.com\/company\/pixelloid-studios-private-limited","visibleUrl":"www.linkedin.com"},{"content":"The latest from <b>Pixelloid<\/b> (@<b>Pixelloid<\/b>). <b>Pixelloid<\/b> is an award winning 3D   Animation &amp; Visual Effects studio with a dedicated commercial training division.","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid (Pixelloid) on Twitter","title":"<b>Pixelloid<\/b> (<b>Pixelloid<\/b>) on Twitter","cacheUrl":"http:\/\/www.google.com\/search?q=cache:s4gJgJcovCsJ:twitter.com","unescapedUrl":"https:\/\/twitter.com\/Pixelloid","url":"https:\/\/twitter.com\/Pixelloid","visibleUrl":"twitter.com"},{"content":"Feb 10, 2013 <b>...<\/b> <b>Pixelloid<\/b>, Hyderabad is the only training institute in India that has an active   production environment. <b>Pixelloid&#39;s<\/b> courses are tailored to the <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid - Admission, Courses, Fee, Address | Pixelloid | Hyderabad ...","title":"<b>Pixelloid<\/b> - Admission, Courses, Fee, Address | <b>Pixelloid<\/b> | Hyderabad <b>...<\/b>","cacheUrl":"http:\/\/www.google.com\/search?q=cache:3OWFak05f30J:www.minglebox.com","unescapedUrl":"http:\/\/www.minglebox.com\/college\/pixelloid-Hyderabad","url":"http:\/\/www.mi
{“responseData”:{“结果”:[{“内容”:“Pixelloid工作室视觉效果,3D动画制作和培训学院”,“GsearchResultClass”:“GwebSearch”,“标题信息”:“Pixelloid-视觉效果,3D动画-制作和培训”,“标题”:“Pixelloid-视觉效果,3D动画-制作和培训”,“缓存URL”:http:\/\/www.google.com\/search?q=cache:Uq3\u USWdbwIJ:www.pixelloid.com”,“unescapedUrl:“http:\/\/www.pixelloid.com\/”,“url:“http:\/\/www.pixelloid.com\/”,“visibleUrl:“www.pixelloid.com”,“{“内容”:“pixelloid工作室视觉效果、3D动画制作和培训…”,“GsearchResultClass:“GwebSearch”,“titlenoformating:”生产和培训机构-Pixelloid,“标题”:“生产和培训机构-Pixelloid”,“cacheUrl”:“http:\/\/www.google.com\/search?q=cache:Pce2UIgSVDoJ:www.Pixelloid.com”,“unescapedur”:“http:\/\/www.Pixelloid.com\/Training\/”,“url”:“http:\/\/\/www.Pixelloid.com\/Training\/”,“visibleUrl”:“www.pixel.com”,{“内容”:Pixelloid是一家屡获殊荣的3D动画和视觉效果制作及培训工作室,总部位于海得拉巴,在班加罗尔、维萨卡帕特南设有分公司……,“GsearchResultClass”:“GwebSearch”,“Titlenoformating”:“Pixelloid工作室-YouTube”,“title”:“Pixelloid工作室-YouTube”,“cacheUrl”:http:\/\/www.google.com\/search?q=cache:wrfWBrpn45AJ:www.youtube.com,“unescapedur”:“http:\/\/www.youtube.com\/user\/pixelloid”,“url”:“http:\/\/www.youtube.com\/user\/pixelloid”,“visibleUrl”:“www.youtube.com”},{“content”:Pixelloid,印度海得拉巴。5896个喜欢。60个谈论这个。408个在这里。我们帮助人们有效地讲述他们的故事。我们为…制作动画,视觉效果,“GsearchResultClass”:“GwebSearch”,“Titlenoformating”:“Pixelloid-印度海得拉巴-媒体\/新闻\/出版| Facebook”,“title”:Pixelloid-印度海得拉巴-Media\/News\/Publishing | Facebook”,“cacheUrl:“http:\/\/www.google.com\/search?q=cache:"m-PNJ9c3sgJ:www.Facebook.com”,“unescapedUrl:"https:\/\/www.Facebook.com\/Pixelloid”,“url:"https:\/\/\/www.Facebook.com\/Pixelloid”,“visibleUrl:"www.Facebook.com”,{“content:"欢迎访问LinkedIn上Pixelloid Studios Private Limited的公司简介。Pixelloid是一家屡获殊荣的内容创作公司,拥有一个活跃的……,“GsearchResultClass”:“GwebSearch”,“Titlenoformating”:“Pixelloid Studios”
{"responseData":{"results":[{"content":"<b>Pixelloid<\/b> Studios Visual Effects, 3D Animation Production and Training Institute.","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid - Visual Effects, 3D Animation - Production and Training","title":"<b>Pixelloid<\/b> - Visual Effects, 3D Animation - Production and Training","cacheUrl":"http:\/\/www.google.com\/search?q=cache:Uq3_USWdbwIJ:www.pixelloid.com","unescapedUrl":"http:\/\/www.pixelloid.com\/","url":"http:\/\/www.pixelloid.com\/","visibleUrl":"www.pixelloid.com"},{"content":"Pixelloid Studios Visual Effects, 3D   Animation Production and Training <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Production and Training Institute - Pixelloid","title":"Production and Training Institute - <b>Pixelloid<\/b>","cacheUrl":"http:\/\/www.google.com\/search?q=cache:Pce2UIgSVDoJ:www.pixelloid.com","unescapedUrl":"http:\/\/www.pixelloid.com\/training\/","url":"http:\/\/www.pixelloid.com\/training\/","visibleUrl":"www.pixelloid.com"},{"content":"<b>Pixelloid<\/b> is an award winning 3D Animation &amp; Visual Effects Production and   Training Studio based in Hyderabad with branches in Bangalore, Visakhapatnam   <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid Studios - YouTube","title":"<b>Pixelloid<\/b> Studios - YouTube","cacheUrl":"http:\/\/www.google.com\/search?q=cache:wrfWBrpn45AJ:www.youtube.com","unescapedUrl":"http:\/\/www.youtube.com\/user\/pixelloid","url":"http:\/\/www.youtube.com\/user\/pixelloid","visibleUrl":"www.youtube.com"},{"content":"<b>Pixelloid<\/b>, Hyderabad, India. 5896 likes · 60 talking about this · 408 were here. We   help people tell their stories effectively. We do animation, visual effects for <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid - Hyderabad, India - Media\/News\/Publishing | Facebook","title":"<b>Pixelloid<\/b> - Hyderabad, India - Media\/News\/Publishing | Facebook","cacheUrl":"http:\/\/www.google.com\/search?q=cache:_m-PNJ9c3sgJ:www.facebook.com","unescapedUrl":"https:\/\/www.facebook.com\/Pixelloid","url":"https:\/\/www.facebook.com\/Pixelloid","visibleUrl":"www.facebook.com"},{"content":"Welcome to the company profile of <b>Pixelloid<\/b> Studios Private Limited on LinkedIn.   <b>Pixelloid<\/b> is an award winning Content Creation Company with an active <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid Studios Private Limited | LinkedIn","title":"<b>Pixelloid<\/b> Studios Private Limited | LinkedIn","cacheUrl":"http:\/\/www.google.com\/search?q=cache:vnyg3sUrGfgJ:www.linkedin.com","unescapedUrl":"http:\/\/www.linkedin.com\/company\/pixelloid-studios-private-limited","url":"http:\/\/www.linkedin.com\/company\/pixelloid-studios-private-limited","visibleUrl":"www.linkedin.com"},{"content":"The latest from <b>Pixelloid<\/b> (@<b>Pixelloid<\/b>). <b>Pixelloid<\/b> is an award winning 3D   Animation &amp; Visual Effects studio with a dedicated commercial training division.","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid (Pixelloid) on Twitter","title":"<b>Pixelloid<\/b> (<b>Pixelloid<\/b>) on Twitter","cacheUrl":"http:\/\/www.google.com\/search?q=cache:s4gJgJcovCsJ:twitter.com","unescapedUrl":"https:\/\/twitter.com\/Pixelloid","url":"https:\/\/twitter.com\/Pixelloid","visibleUrl":"twitter.com"},{"content":"Feb 10, 2013 <b>...<\/b> <b>Pixelloid<\/b>, Hyderabad is the only training institute in India that has an active   production environment. <b>Pixelloid&#39;s<\/b> courses are tailored to the <b>...<\/b>","GsearchResultClass":"GwebSearch","titleNoFormatting":"Pixelloid - Admission, Courses, Fee, Address | Pixelloid | Hyderabad ...","title":"<b>Pixelloid<\/b> - Admission, Courses, Fee, Address | <b>Pixelloid<\/b> | Hyderabad <b>...<\/b>","cacheUrl":"http:\/\/www.google.com\/search?q=cache:3OWFak05f30J:www.minglebox.com","unescapedUrl":"http:\/\/www.minglebox.com\/college\/pixelloid-Hyderabad","url":"http:\/\/www.mi
{
  "responseData": {
     "results": [],
     "cursor": {
         "moreResultsUrl": "http://www.url.com",
         "searchResultTime": "0,00"
     }
  },
  "responseDetails": null,
  "responseStatus": 200
}
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;

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

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;

public class MainActivity extends ListActivity { 

private Context context; 
private static String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=pixelloid&rsz=8";

private static final String TAG_content = "content";
private static final String TAG_GsearchResultClass = "GsearchResultClass";
private static final String TAG_titleNoFormatting = "titleNoFormatting";
private static final String TAG_title = "title";
private static final String TAG_cacheUrl = "cacheUrl";
private static final String TAG_unescapedUrl = "unescapedUrl";
private static final String TAG_url = "url";
private static final String TAG_visibleUrl = "visibleUrl";



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    new ProgressTask(MainActivity.this).execute();
}

private class ProgressTask extends AsyncTask<String, Void, Boolean> {
    private ProgressDialog dialog;

    private ListActivity activity;

    // private List<Message> messages;
    public ProgressTask(ListActivity activity) {
        this.activity = activity;
        context = activity;
        dialog = new ProgressDialog(context);
    }

    /** progress dialog to show user that the backup is processing. */

    /** application context. */
    private Context context;

    protected void onPreExecute() {
        this.dialog.setMessage("Progress start");
        this.dialog.show();
    }

    @Override
    protected void onPostExecute(final Boolean success) {
        if (dialog.isShowing()) {
            dialog.dismiss();
        }
        ListAdapter adapter = new SimpleAdapter( context, contents, R.layout.list_item, 
                                    new String[] { TAG_title, TAG_content, TAG_url }, 
                                    new int[] { R.id.vehicleType, R.id.vehicleColor, R.id.fuel, R.id.treadType });

        setListAdapter(adapter);

        // selecting single ListView item
        //lv = getListView();
    }

    protected Boolean doInBackground(final String... args) {
            loadJson();
            return null;
    }
}

public static JSONObject parse() {
    JSONParser parser = new JSONParser();
    Object obj;
    JSONObject json = new JSONObject();
    try {
        obj = parser.getJSONFromUrl(url);
        json=(JSONObject)obj;
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return json;
}

private String moreResultsUrl = "";
private ArrayList<HashMap<String, String>> contents;

public void loadJson() {

    try {
        JSONObject obj = parse();
        if(obj!=null) {
             JSONObject responseData;
             responseData = (JSONObject ) obj.get("responseData");

             if(responseData !=null) {
                JSONArray results =  (JSONArray) obj.get("results"); 
                contents = new ArrayList<HashMap<String, String>>();

                HashMap<String, String> map;
                JSONObject cro;
                for(int i=0;i<results.length();i++) {
                    map = new HashMap<String, String>();
                    cro = (JSONObject) results.get(i);

                    map.put(TAG_content, cro.get(TAG_content).toString() );
                    map.put(TAG_GsearchResultClass, cro.get(TAG_GsearchResultClass).toString() );
                    map.put(TAG_titleNoFormatting, cro.get(TAG_titleNoFormatting).toString() );
                    map.put(TAG_titleNoFormatting, cro.get(TAG_titleNoFormatting).toString() );
                    map.put(TAG_title, cro.get(TAG_title).toString() );
                    map.put(TAG_cacheUrl, cro.get(TAG_cacheUrl).toString() );
                    map.put(TAG_unescapedUrl, cro.get(TAG_unescapedUrl).toString() );
                    map.put(TAG_url, cro.get(TAG_url).toString() );
                    map.put(TAG_visibleUrl, cro.get(TAG_visibleUrl).toString() );

                    contents.add(map);
                }

                JSONObject cursor =  (JSONObject ) responseData.get("cursor");
                if(cursor!=null)  moreResultsUrl = cursor.get("moreResultsUrl").toString();
             }
         }

    } catch (JSONException e) {
        e.printStackTrace();
    }
}