J'utilise Kairos API, la demande d'inscription est réussie, je le vois sur Kairos Dashboard. Malheureusement, je ne peux pas saisir la requête formatée JSON
, que j'essaie de stocker dans une chaîne. La réponse devrait ressembler à ceci:Réponse Catch Json dans l'application Android
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%"
}
}
}]
}
J'essaie d'utiliser ce code. Le résultat est une chaîne vide.
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 "";
}
}
post convertinputStreamToString() fonction –
@Abhi: Ajoutée. Merci! – plaidshirt
pourquoi n'utilisez-vous pas la bibliothèque de volley? –