我一直在尝试解析JSON文件。它有点偏离结构,因此,为了进入一个结构,我使用该文件的子序列(以便它进入一个结构)。 但是当我使用子序列或子串时,它只是省略了起始(第一个偏移)而不是结束偏移(结束就是这样)。 这是代码:
String url = "http://earthquake.usgs.gov/earthquakes/feed/geojsonp/2.5/week"; //json file
String response="";
response = getInputStreamFromUrl(url); //getting the response
response= response.subSequence(16, response.length()-2).toString(); //i want to omit the last 2 characters from the string
txt.setText(response); //setting the response in a text view(doing it in android)
我还尝试过对字符进行计数,然后设置结束偏移量,但仍然省略了超过指定的字符数。