从JSON中获取字符串,如Java中的PHP

从JSON中获取字符串,如Java中的PHP,java,json,org.json,Java,Json,Org.json,我想知道是否有一种方法可以像PHP一样从Java中的JSON获取字符串: <?php $json = @file_get_contents('example'); $decoded_json = json_decode($json); echo $decoded_json->{"something"} ; ?> 但是,它给了我这个错误: org.json.JSONException: A JSONObject text must begin with '{' at 1 [c

我想知道是否有一种方法可以像PHP一样从Java中的JSON获取字符串:

<?php
$json = @file_get_contents('example');

$decoded_json = json_decode($json);
echo $decoded_json->{"something"} ;
?>
但是,它给了我这个错误:

org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]

谢谢

这是因为您的字符串不是有效的JSON对象,而是包含对象的有效JSON数组,请尝试使用JSONArray,然后您可以在该数组中查询所需的对象\“当一个双引号位于另一个双引号内时

您对错误有什么不理解?似乎应该转义json字符串中使用的引号。Ooopsy给出了错误的代码。正确的人让他们逃跑了。
org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]