-3

PHPホストからjson応答を受け取っています

{"uid": "0"}

私はそれから0(すなわちuid値)を取得したい

私はそれを取得しようとしました..しかし例外がありました

これは私のコードです..

    HttpEntity entity = response.getEntity();

} catch(Exception e) {
    System.out.println("Exception : " + e.getMessage());
}
finally {
    if (conn != null) {
        try {  
            conn.close ();
        }
        catch (Exception e) { e.printStackTrace(); }  
    }
}

//convert response to string
/*
try {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"),8);
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
        sb.append(line+"\n");
    }
    is.close();
    result = sb.toString();
} catch(Exception e) {
    System.out.println("Exception : " + e.getMessage());
}
try
{
    ??????????????????????????
} catch(Exception e) { e.printStackTrace(); }
4

2 に答える 2

2

JSONOBJECTを使用するだけです。

JSONObject obj = new JSONObject(src);
if (obj.has("uid")){
   String uid = obj.getString("uid");
}
于 2012-10-30T18:26:29.507 に答える
0

GSONを使用すると、これが非常に簡単になります

于 2012-10-30T18:54:23.803 に答える