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 获取并解析这段数据 要怎么做?
请给出代码提示,谢谢!
{"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 获取并解析这段数据 要怎么做?
请给出代码提示,谢谢!
解决方案 »
- 新手求教,关于多选dialog 多选项限定
- Activity生命周期问题。
- Android广播问题,急急急急!!!
- android中怎么通过代码获取Logcat信息,和自定义的filter logcat最好是自定义的。先谢谢大家。
- 怎么使android手机不锁屏,解锁后等几分钟就会早就锁定~~~~~~~~·
- android 伪装定位是怎么做的
- 程序报错
- 使用Android Studio调试程序时候出现这个错误:Error:Execution failed for task ':app:clean'.
- AVD打开新建的模拟器,屏幕一直是黑色的,不知道怎么回事
- Android studio从2.3更新到3.1后,logcat工具显示的就有问题,实在影响分析log,有没有解决的办法啊?
- 如何从Surface得到ISurfaceTexture
- 百度地图搭建出现的问题,望赐教!
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()); 这一行 报错了 }
<?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>
有加啊