-1
JSONをwebpageから読み込んでいます。これをPHPのように配列に変換して使用します。私はこのクラスを使用するWebからJSON文字列を取得するには、Android Studioで、AndroidスタジオでJSONをPHPスタイルで使用する
//$json - this is my json STRING readed from webpage
$trueJSON = json_decode($json,true);
$q = $trueJSON['test']['questions'][1]['question'];
$a1 = $trueJSON['test']['questions'][1]['answers']['a1'];
$a2 = $trueJSON['test']['questions'][1]['answers']['a2'];
$a3 = $trueJSON['test']['questions'][1]['answers']['a3'];
$a4 = $trueJSON['test']['questions'][1]['answers']['a4'];
$a5 = $trueJSON['test']['questions'][1]['answers']['a5'];
$a = $trueJSON['test']['questions'][1]['correctAnswer'];
:
public class TalkToServer extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
}
@Override
protected String doInBackground(String... params) {
String response = HttpRequest.get(params[0]).body();
return response;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// and here I want to decode JSON string result to Array
// and next use this array on whole Activity
}
}
public void click(View view) {
TalkToServer task = new TalkToServer();
task.execute("http://quiz.xnicram.pl/getTest.php");
}
可能ならば、私は使用することができますonPostExecute
配列で作成する方法PHPで私はそのようにそれを行います私のPHPの例と同様の方法で?
PS。私の英語のため申し訳ありません:/
を使用することができ、私は '/ *アレイ名* /'タイプ「テスト」、「名前」、「質問」と私が得たすべての時間の代わりにしてみてくださいエラーメッセージ "... JSONArrayに変換できません"、ここにJSONデータhttp://kiz.xnicram.pl/getTest.phpのJSON – MastaBot
があります。これはJSONデータのフォーマットが無効なためです –
json string私はいくつかのツールでそれをチェックします – MastaBot