2016-03-25 13 views
1

Im einzurahmen zu erstellen versuchen, ein JSON-Array wie folgtkann nicht jsonarray

[ 
"Login", 
{ 
    "login_type": "Android", 
    "username": "[email protected]", 
    "password": "123", 
    "short_name": null, 
    "ip": "122.164.164.35" 
} 
] 

Im Anschluss an mein Code,

public JSONArray frameLoginJson() { 
     JSONObject jsonObject = new JSONObject(); 
     try { 
      jsonObject.put("login_type", "Android"); 
      jsonObject.put("username", email); 
      jsonObject.put("password", password); 
      jsonObject.put("short_name", null); 
      jsonObject.put("ip", "124.5.67.3"); 

     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 



     JSONArray jsonArray = new JSONArray(); 
     jsonArray.put(jsonObject); 

     //Toast.makeText((), "" + jsonObject, Toast.LENGTH_SHORT).show(); 
     return jsonArray; 
    } 

Das Problem ist, dass es nicht die json genau Framing ist. Wo fehlt mir der Punkt?

+2

müssen auch '' Einloggen String in jsonArray als hinzuzufügen: 'jsonArray.put ("Login"); jsonArray.put (JSONObject);' –

+0

es Sie arbeitet jetzt danken –

Antwort

2
JSONArray jsonArray=new JSONArray(); 
jsonArray.put("Login"); 
     JSONObject jsonObject=new JSONObject(); 
     try { 
      jsonObject.put("login_type", "Android"); 
      jsonObject.put("username", email); 
      jsonObject.put("password", password); 
      jsonObject.put("short_name", null); 
      jsonObject.put("ip", "124.5.67.3"); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 


jsonArray.put(jsonObject);