먼저 아래 코드를 사용해 된 JSONObject에 대한 HTTP 스트림에서 읽은 문자열을 변환하는 것입니다. 아래
String url="Your URL Goes Here";
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response;
try {
try
{
InetAddress i = InetAddress.getByName(url);
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
String result= convertStreamToString(instream);
stringContent=new StringContent(result);
instream.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
그리고 convertStreamToString
블록
입니다 : 내 HTTP 코드를 얻을 여기에 지금
String reference1=jsonobject.getString("Reference1");
referece1의 값 = String content
을 그리고 : 코드의 경우는 같은 것을 할 것
private static String convertStreamToString(InputStream is)
{
/*
* To convert the InputStream to String we use the BufferedReader.readLine()
* method. We iterate until the BufferedReader return null which means
* there's no more data to read. Each line will appended to a StringBuilder
* and returned as String.
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
JSON이 아닌 JSON입니다. – Quentin
@Quentin,하지만이 작업은 JSONP 응답을 지원합니다. 콜백 함수는 "콜백"URL 쿼리 매개 변수를 사용하여 지정할 수 있습니다. 도움말 페이지에서 .. – wolverine
- 브라우저에서 실행되는 JS를 작성하지 않으므로 JSONP가 필요하지 않으므로 선택적으로 제공 할 수있는 서비스의 기능은 적절하지 않습니다. – Quentin