私はKairos APIを使用しています。登録リクエストが成功しました。カイロスダッシュボードで表示されます。残念ながら私はJSON
のフォーマットされたリクエストをキャッチできません。これは文字列に格納しようとします。応答は次のようになります。AndroidアプリのCatch Jsonレスポンス
200
Content-Type: application/json
{
"images": [
{
"time": 3.43817,
"transaction": {
"status": "success",
"face_id": "685ff4b47a3db8579efd2fa6a7d9293b",
"subject_id": "subtest1",
"width": 934,
"height": 934,
"topLeftX": 300,
"topLeftY": 526,
"timestamp": "1417207442",
"gallery_name": "gallerytest1"
},
"attributes": {
"gender": {
"type": "F",
"confidence": "80%"
}
}
}]
}
このコードを使用しようとしています。 結果は空の文字列です。
public String jsonParsing(){
String parsedString = "";
try {
String urlStr = "https://api.kairos.com/enroll";
URL url = new URL(urlStr);
URLConnection conn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
InputStream is = httpConn.getInputStream();
parsedString = convertinputStreamToString(is);
} catch (Exception e) {
e.printStackTrace();
}
return parsedString;
}
convertinputStreamToString():
public static String convertinputStreamToString(InputStream ists)
throws IOException {
if (ists != null) {
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader r1 = new BufferedReader(new InputStreamReader(
ists, "UTF-8"));
while ((line = r1.readLine()) != null) {
sb.append(line).append("\n");
}
} finally {
ists.close();
}
return sb.toString();
} else {
return "";
}
}
投稿convertinputStreamToString()関数 –
@Abhi:追加されました。ありがとう! – plaidshirt
なぜあなたはvolleyライブラリを使用しないのですか? –