[英]how to get the text from JSON response using simple java code
大家好,执行REST请求时,我得到以下响应。
["A103388","R101858","R5575"]
但是我需要括号[]之间的值。 我尝试使用split()
和replace()
但无法实现。
无需拆分 。 如果您使用JSONObject
JSONObject object = new JSONObject(response_message); //["A103388","R101858","R5575"]
for(int i = 0; i<object.length() ; i++)
{
String getValue= object.get(i);
}
其他方式
String getValue="your_respose";
String [] getSplit=getValue.split(",");
for(int i = 0; i < getSplit.length; i++)
{
System.out.println("Amiyo"+getSplit[i]);
}
为了获得各个值,可以使用以下代码:
String input = "[\"A103388\",\"R101858\",\"R5575\"]"
String[] parsedInput = input.replaceAll("[\[\]]", "").split(",")
这段代码将所有括号都替换为input.replaceAll("[\\[\\]]", "")
,实际上将其删除( input.replaceAll("[\\[\\]]", "")
),然后将其在逗号( .split(",")
)上分割。 这将导致一个String数组,该数组将每个请求的元素作为元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.