Java 如何从特殊格式字符串中获取值?

Java 如何从特殊格式字符串中获取值?,java,android,json,string,Java,Android,Json,String,我从web api获得一个字符串,如{“time”:“08:05”,“code”:“CSTM”,“name”:“MUMBAI CST”},该字符串不能转换为JSONObject,因此我无法从该字符串中获取值。如何从字符串中获取值 link = new URL("The url"); InputStream in = link.openStream(); LoadRegistration_Api(in); p

我从web api获得一个字符串,如{“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。。。为什么?请给出用于将上述字符串转换为json的代码?谢谢大家。我找到了解决办法。文本是JSON,但这是我的错误。