-1
我收到了一个字符串,如{“time”:“08:05”,“code”:“CSTM”,“name”:“MUMBAI CST”},该字符串不能转换为JSONObject,原因我无法从字符串中获得价值。我怎样才能从字符串中获得价值?如何从特殊格式字符串获取值?
我收到了一个字符串,如{“time”:“08:05”,“code”:“CSTM”,“name”:“MUMBAI CST”},该字符串不能转换为JSONObject,原因我无法从字符串中获得价值。我怎样才能从字符串中获得价值?如何从特殊格式字符串获取值?
link = new URL("The url");
InputStream in = link.openStream();
LoadRegistration_Api(in);
protected void LoadRegistration_Api(InputStream json)
throws IOException, JSONException {
// TODO Auto-generated method stub
BufferedReader reader = new BufferedReader(new InputStreamReader(
json));
StringBuilder sb = new StringBuilder();
String line = reader.readLine();
while (line != null) {
sb.append(line);
line = reader.readLine();
}
reader.close();
JSONObject jobj = new JSONObject(sb.toString());
if (jobj.has("time")) // handle Se_wesam
{
Result = jobj.getString("time");
}
if (jobj.has("code")) // handle Se_wesam
{
UserId = jobj.getString("code");
}
}
}
试试这个我认为这将有助于
此字符串无法转换为JSONObject的......为什么? – baboo
给你用于将上述字符串转换为json的代码? – Parvathy
谢谢大家。我找到了解决方案。文本是JSON,但这是我的错误。 – TKumar