2016-08-14 53 views
1

您好,我需要連接一個android應用程序和cloudant,並使用android studio發佈和發佈來自cloudant的json數據,但我不知道如何,請你幫助我嗎?使用android studio獲取來自cloudant的json數據

我嘗試使用凌空連接時,我使用SQLite連接,但我不知道如何與cloudant

public class MainActivity extends AppCompatActivity { 

TextView nombre; 
TextView email; 
TextView telefono; 
Button button; 
String json_url = "https://jesusjrod19.cloudant.com/gsus/usuarios"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    button = (Button)findViewById(R.id.bn); 
    nombre = (TextView)findViewById(R.id.nombre); 
    email = (TextView)findViewById(R.id.email); 
    telefono = (TextView)findViewById(R.id.telefono); 
    button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,json_url,null, 
        new Response.Listener<JSONObject>() { 
         @Override 
         public void onResponse(JSONObject response) { 

          try { 
           nombre.setText(response.getString("nombre")); 
           email.setText(response.getString("email")); 
           telefono.setText(response.getString("telefono")); 

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

         } 
        }, new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 

        Toast.makeText(MainActivity.this,"zaraza", Toast.LENGTH_SHORT).show(); 
        error.printStackTrace(); 

       } 
      }); 

      MySingleton.getInstance(MainActivity.this).addToRequestque(jsonObjectRequest); 




     } 
    }); 

} 

}

回答