2016-07-25 17 views
0

私はアンドロイドの初心者です。これ以上の助けをしてください。例外の取得:org.json.JSONObjectをJSONArrayに変換できません

私はまだ私は

org.json.JSONException取得していますJSONArrayにそれを変換した

try { 
JSONArray jArray = new JSONArray(result); 
// Extract data from json and store into ArrayList as class objects 
for (int i = 0; i < jArray.length(); i++) { 
    JSONObject json_data = jArray.getJSONObject(i); 
    DataFish fishData = new DataFish(); 
    fishData.nonce = json_data.getString("nonce"); 
    fishData.iUserId = json_data.getString("iUserId"); 
    fishData.timestamp = json_data.getString("timestamp"); 
    fishData.token = json_data.getString("token"); 

    data.add(fishData); 
} 

// Setup and Handover data to recyclerview 
mRVFishPrice = (RecyclerView) findViewById(R.id.fishPriceList); 
mAdapter = new AdapterFish(PostActivity.this, data); 
mRVFishPrice.setAdapter(mAdapter); 
mRVFishPrice.setLayoutManager(new LinearLayoutManager(PostActivity.this)); 

} 
catch (JSONException e) { 
Toast.makeText(PostActivity.this, e.toString(), Toast.LENGTH_LONG).show(); 
} 

:値{ "コード": "0"、 "メッセージ": "アクセスが拒否された、 無効なユーザーをorg.json.JSONObject型の "reference"}は をJSONArrayに変換できません。

+0

JSONデータを投稿してください。 –

+0

まず、コードが0か1かを確認します。配列の値を取得するコードが1の場合 – vinoth12594

+0

コードキーの整数を使用 – vinoth12594

答えて

0

TRY it。

JSONArray alldata = new JSONArray(); 

for(your codition to get data for how many array items in loop){ 
JSONObject all = new JSONObject(); 
all.put("nonce", "G9Ivek"); 
all.put("iUserId", "477"); 
all.put("timestamp","20160614060439"); 
alldata.put(all); 

}

、サーバにALLDATAを送ります。

希望これは

Map<String, String> param = new HashMap<String, String>(); 
        param.put("access_code", access_code); 
        param.put("auth_token", auth_token); 
        param.put("data", objMainList.toString()); 

        try { 
         HttpUtility.sendPostRequest(Config.Submit_Answer, param); 
         String response = HttpUtility.readMultipleLinesRespone(); 
         json = new JSONObject(response); 
         HttpUtility.disconnect(); 

} catch (Exception e) { 

         e.printStackTrace(); 

        } 
+0

サーバにalldataを送信するために何を書きますか? – Rujuta

+0

上記の回答に沿ってサーバーに送信してください。私に教えてください。 – Andolasoft

0

)(私が知っているyou..Let ..

を助けるためにASYNC TASK DOINBACKGROUNDにAPIのURLにバインド日のためにサーバー

JSONObject objMainList = new JSONObject(); 
objMainList.put("ALLDETAILS", alldata); 

に送信しますこれはJSONArrayオブジェクトではありません。これはJSONObjectであり、JSONArrayに対して解析することはできません。詳細については、it hereを参照してください。

関連する問題