친구, 주어진 URL에서 직접 json 콘텐츠를 파싱하는 데 문제가 있습니다. 그러나 내 res/raw 폴더의 텍스트 파일과 동일한 URL 콘텐츠를 저장할 때 다음과 같이 데이터를 구문 분석합니다. 인터넷에서 URL의 컨텐츠를 가져 오는 경우도 있지만, 시작 (예) JSONArray 텍스트는 반드시 예외를 보여줍니다 '['의 문자 하나 ... 내가이 문제를 해결하는 잘못된 here.help가 무엇JSON이 Android 용 URL 콘텐츠를 가져옵니다.
에서 문제
URL url_net = new URL("http://samplejson.com/transactions.json");
InputStream is = url_net.openStream();
byte [] buffer = new byte[is.available()];
while (is.read(buffer) != -1);
String jsontext = new String(buffer);
JSONArray entries = new JSONArray(jsontext);
x = "JSON parsed.\nThere are [" + entries.length() + "]\n\n";
int i;
for (i=0;i<entries.length();i++) { }
OK : 여기
내가하는 HTTP GET의 문자열 콘텐츠를 얻기 위해 사용하는 코드입니다. JSON 자체를 살펴 보았지만 괜찮았다. – AliostadURL url_net = 새 URL ("http://184.106.227.45/quaddeals/university-of-illinois/androids/transactions/type:available/752/transactions.json"); \t \t InputStream is = url_net.openStream(); \t \t 바이트 [] 버퍼 = 새 바이트 [is.available()]; \t \t while (is.read (buffer)! = -1); \t \t 문자열 jsontext = new 문자열 (버퍼); \t \t JSONArray 항목 = 새 JSONArray (jsontext); \t \t \t \t x = "JSON 구문 분석. \ n ["+ entries.length() + "] \ n \ n"; \t \t \t int i; \t \t (i = 0; i