我需要从这个JSON中获取 id 我该如何获得它? id 可动态更改。
[{"id":"e28bad5b-661e-4026-983f-60e809a9cd32","name":"kjgkjgk","status":"HEALTHY","containers":[{"id":"f397c436-7701-4965-acff-980bee1b1ebd","environmentId":"e28bad5b-661e-4026-983f-60e809a9cd32","hostname":"master1d1ea96172224bff98214e57f1839a48"]}
答案 0 :(得分:1)
首先,您需要创建json的对象并在此对象中传递jsonobject名称。 通过使用此对象,您可以轻松获取字符串标记。
String data=[{"id":"e28bad5b-661e-4026-983f-60e809a9cd32","name":"kjgkjgk","status":"HEALTHY","containers":[{"id":"f397c436-7701-4965-acff-980bee1b1ebd","environmentId":"e28bad5b-661e-4026-983f-60e809a9cd32","hostname":"master1d1ea96172224bff98214e57f1839a48"]};
JSONArray jsonArray = new JSONArray(data);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
String id = jsonObject.getString("id");
}
如上所述为id做其余的
答案 1 :(得分:0)
String id = data.getText().substring(8, 44);
那就是它。