PHP的JSON数据:
{"posts":[{"post":{"idusers":"1","username":"Allen","fullname":"AllenAllen"}},{"post":{"idusers":"2","username":"Alice","fullname":"AliceAlice"}}]Http  url:"http://192.168.1.109:8080/TestWeb/webservice1.php?user=1&format=json"我要通过Http 获取并解析这段数据  要怎么做?
请给出代码提示,谢谢!

解决方案 »

  1.   


    String url="http://192.168.1.109:8080/TestWeb/webservice1.php";
     public void B(String url)
     {
     try {
     HttpPost request = new HttpPost(url);  
    // 先封装一个 JSON 对象   
    JSONObject param = new JSONObject();  

    param.put("user", "1");
    param.put("format", "json");


    // param.put("password", "123456");  
    // 绑定到请求 Entry   
     StringEntity se = new StringEntity(param.toString());   
     request.setEntity(se);  
    // 发送请求   
     HttpResponse httpResponse = new DefaultHttpClient().execute(request);  
    // 得到应答的字符串,这也是一个 JSON 格式保存的数据   
     String retSrc = EntityUtils.toString(httpResponse.getEntity());        System.out.println(retSrc);
     } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }  我这样写 有报错了:
     String retSrc = EntityUtils.toString(httpResponse.getEntity());  这一行  报错了    }
      

  2.   


    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.httptest"
        android:versionCode="1"
        android:versionName="1.0" >    <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="16" />
           <uses-permission android:name="android.permission.INTERNET" />
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.httptest.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>
    有加啊
      

  3.   

    http://192.168.1.109:8080/TestWeb/webservice1.php?user=1&format=json应该是GET请求方式。