【发布时间】:2018-06-09 21:47:26
【问题描述】:
我知道这个问题得到了绝对回答,但我没有找到解决方案。 我从 Web 服务获得响应为 ["11,22222","33,44444"] 的 Json 字符串响应。
我尝试了这个但没有用,因为字符串包含这些字符 [ ] 并且第一个逗号在这里 11,22
StringBuilder result = new StringBuilder();
URL url2 = new URL(url);
HttpURLConnection conn = (HttpURLConnection) url2.openConnection();
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
String res = new String(result);
String [] coordinates = res.split(",");
我怎样才能分离这个字符串,如“11,22222”和“33,44444”
【问题讨论】:
-
您可以将其转换为 JsonObject,然后它将像数组一样工作。其他解决方法是 res.split("\""); 现在您将获得 1 和 3 索引中的值。
-
什么语言? C#?爪哇?
-
Java 我可以使用 @maddy23285 解决方案作为 res.split("\"");
标签: arrays json string web-services http