小编cof*_*ffy的帖子

将Json解析为String android studio

我有这个JSON对象:

{
  "1":{
    "id_module":"f83d6101cc",
    "adresse_mac":"00:6A:8E:16:C6:26",
    "mot_de_passe":"mp0001","name":"a"
  },  
  "2":{
    "id_module":"64eae5403b",
    "adresse_mac":"00:6A:8E:16:C6:26",
    "mot_de_passe":"mp0002",
    "name":"a"
  }
}
Run Code Online (Sandbox Code Playgroud)

而且我想解析,并获得字符串id_module,adresse_mac,mot_de_passename每个事物的1和2.

所以我做了这个,但它不起作用:

TextView txt1=(TextView) findViewById(R.id.textView);
String ajout1 = "http://";
JSONObject json = null;
String str = "1";
HttpResponse response;
HttpClient myClient = new DefaultHttpClient();
HttpPost myConnection = new HttpPost(ajout1);
try {
    response = myClient.execute(myConnection);
    str = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
try {
    JSONObject jsonObject = new JSONObject(str); …
Run Code Online (Sandbox Code Playgroud)

java android json

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

java ×1

json ×1