私の URL は .php 形式です: ホスト名/ファイル名/topstory.php
解析中に次のエラーが発生します....
11-28 09:47:57.603: E/class com.example.jsonexample.AndroidJSONActivity(749): Failed to download file
11-28 09:47:57.603: W/System.err(749): org.json.JSONException: End of input at character 0 of
11-28 09:47:57.638: W/System.err(749): at org.json.JSONTokener.syntaxError(JSONTokener.java:446)
11-28 09:47:57.638: W/System.err(749): at org.json.JSONTokener.nextValue(JSONTokener.java:93)
11-28 09:47:57.654: W/System.err(749): at org.json.JSONArray.<init>(JSONArray.java:87)
11-28 09:47:57.654: W/System.err(749): at org.json.JSONArray.<init>(JSONArray.java:103)
11-28 09:47:57.667: W/System.err(749): at com.example.jsonexample.AndroidJSONActivity.onCreate(AndroidJSONActivity.java:34)
11-28 09:47:57.673: W/System.err(749): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-28 09:47:57.673: W/System.err(749): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-28 09:47:57.673: W/System.err(749): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-28 09:47:57.673: W/System.err(749): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-28 09:47:57.683: W/System.err(749): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-28 09:47:57.683: W/System.err(749): at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 09:47:57.683: W/System.err(749): at android.os.Looper.loop(Looper.java:123)
11-28 09:47:57.698: W/System.err(749): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-28 09:47:57.698: W/System.err(749): at java.lang.reflect.Method.invokeNative(Native Method)
11-28 09:47:57.698: W/System.err(749): at java.lang.reflect.Method.invoke(Method.java:521)
11-28 09:47:57.698: W/System.err(749): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-28 09:47:57.698: W/System.err(749): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-28 09:47:57.698: W/System.err(749):
これは私のコードです:
public class AndroidJSONActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(getApplicationContext(),"sdasdsadsa231",2100).show();
String readTwitterFeed = readTwitterFeed();
try {
JSONArray jsonArray = new JSONArray(readTwitterFeed);
Log.i(AndroidJSONActivity.class.getName(),
"Number of entries " + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Log.i(AndroidJSONActivity.class.getName(), jsonObject.getString("text"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
private String readTwitterFeed() {
Toast.makeText(getApplicationContext(),"sdasdsadsa231",3100).show();
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("....../video.php");
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
Toast.makeText(getApplicationContext(),"sdasdsadsa",4000).show();
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
Log.e(AndroidJSONActivity.class.toString(), "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"sdasdsa323424326a",4000).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"sdasdsa323424326a",4000).show();
e.printStackTrace();
}
return builder.toString();
}
}
私のファイル...
{"view":"topstory","content":[{"story_id":"128","title":"testuser2","story_description":"
testuser2<\/p>","story_video_file":"","story_video_link":"","images":..
ファイルを観察してください。データの間に行スペースがあります (後)
story_description":" ),
そのスペースに問題はありますか..これに対する解決策を提案してください....