当前位置: 首页 > 知识库问答 >
问题:

在java中,JSONObject文本必须在1[字符2行1]处以“{”开头

南宫奇思
2023-03-14
private String getUrls(String urlapi) throws IOException, JSONException {
            InputStream in = null;
            in = connectTo(urlapi);
            String result = requestResponseAsString(in);
            String fullResult = parseJSON(result);
            return fullResult;

        }

        private String parseJSON(String result) throws JSONException {
            String url = null;
            JSONObject jObject = new JSONObject(result);
            JSONArray arr = jObject.getJSONArray("Results");
            if(arr.length()>0){
                url = arr.getJSONObject(0).getString("FirstURL");
                System.out.println(url);}
            return url;
        }

共有1个答案

冀弘济
2023-03-14

JSONObject文本必须以“{”错误开头,

JSON对象遵循以下结构:

{
 "array": [
{
    color: "red",
    value: "#f00"
},
{
    color: "green",
    value: "#0f0"
}
]
}

JSON数组遵循以下结构:

[
 { "firstName":"John" , "lastName":"Doe" }, 
 { "firstName":"Anna" , "lastName":"Smith" }, 
 { "firstName":"Peter" , "lastName": "Jones" }
]
 类似资料: