私は過去4日間これを把握しようとしていましたが、私は髪を引き出しようとしています!JSONを解析できませんアプリケーションでは
私はあなたの助けが必要です、誰かが間違って何を言っているのですか?ここで
は、私が開発に使用していますJSON形式のリンクです:プライバシーのために取り外さここ
に関する私のコードです:
public class JSONActivity extends Activity {
TextView http;
HttpClient client;
JSONObject json;
final static String URL = "REMOVED FOR PRIVACY CONCERNS
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
http = (TextView) findViewById(R.id.http);
client = new DefaultHttpClient();
new Read().execute("firstName");
}
public JSONObject getpw(String password)
throws ClientProtocolException, IOException, JSONException {
StringBuilder url = new StringBuilder(URL);
url.append(password);
HttpGet get = new HttpGet(url.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity e = r.getEntity();
String data = EntityUtils.toString(e);
JSONArray getname = new JSONArray(data);
JSONObject last = getname.getJSONObject(3);
return last;
} else {
Toast.makeText(JSONActivity.this, "error", Toast.LENGTH_SHORT);
return null;
}
}
public class Read extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
try {
json=getpw("trustme");
return json.getString(arg0[0]);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
http.setText(result);
}
}}
任意の助けいただければ幸いです。
あなたの問題が何であるかを説明するために非常に大きな助けをしています... – andreapier
私の問題は、アプリケーションが "firstName"を取得するのに失敗し、何らかのデータ交換が行われているのがわかります。 –
あなたのアプリにログを書き込んで、何が起こっているのかを確認します。 Logged( "YourTag"、 "Test hit this line"); ' – Blundell