【发布时间】:2020-07-01 20:44:12
【问题描述】:
我的计划是通过 tensorflow 分析图像并将结果发送到应用程序。 Der 结果写入 json 文件。 json文件长这样:
{"file": "image.jpg", "objects": [{"bbox": [177, 14, 508, 773], "label": "spanishguitar", "prob": 0.7284}]
我在 android studio 中的课程是:
`
private class Downloadjson extends AsyncTask<Void, Void, Void> {
String name;
String label;
public Downloadjson(String name) {
this.name = name;
}
@Override
protected Void doInBackground(Void... params) {
String url = SERVER_ADRESS + name;
sleep(5000);
//animation start
for (int i = 0; i < 600; i++) {
HttpClient client = new DefaultHttpClient(getHttpRequestParams());
HttpGet getJson = new HttpGet(url);
try {
HttpResponse jsonResponse = client.execute(getJson);
if (200 == jsonResponse.getStatusLine().getStatusCode()) {
try {
InputStream inputStream = jsonResponse.getEntity().getContent();
String json = IOUtils.toString(inputStream);
Downloadjson downloadjson = new Gson().fromJson(json, Downloadjson.class);
String label = downloadjson.label;
TextView Result = (TextView) findViewById(R.id.textView);
Result.setText("Your instrument could be a " + downloadjson.label);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
//exucte
sleep(5000);
}
//stop animation
return null;
}
`
当我将“标签”更改为“文件”时,它可以工作并且输出是“image.jpg”。但我需要输出“spanishguitar”的“标签”数组。所以,我认为问题在于,对象不是“标签”而是“对象”(在我的 json 文件中)。 label 是一个数组?你知道我必须改变什么才能获得“标签”吗?
【问题讨论】:
-
“加载到应用程序”如何?您已将此标记为 javascript,但这些都不是 javascript 逻辑
标签: java json android-studio