我必須在以下URL數據發送到web服務如何使用JSON將數據發佈到Web服務?
要被髮送的數據的格式是:
new_member=[{"email":"[email protected]","username":"himanshu01","pwd":"himanshu01"}]
其中email
,username
和pwd
是關鍵,並且具有相應的值的字符串通過的EditText取出串。我點擊按鈕發佈這些數據。
我沒有得到任何迴應bcoz我試圖反擊檢查與我的合作開發人員在他的iPhone相同的應用程序iPhone版的用戶名和密碼無效是由服務器說。
我Signup.java
類是:
Button b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener()
{
EditText e=(EditText)findViewById(R.id.editText1);
String a=e.getText().toString();
EditText e1=(EditText)findViewById(R.id.editText1);
String b=e1.getText().toString();
EditText e2=(EditText)findViewById(R.id.editText1);
String c=e2.getText().toString();
public void onClick(View v) {
// TODO Auto-generated method stub
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;
JSONObject json = new JSONObject();
try{
HttpPost post = new HttpPost("URL");
//System.out.println(post);
json.put("email", a);
json.put("username", b);
json.put("pwd",c);
StringEntity se = new StringEntity("JSON: " + json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setEntity(se);
response = client.execute(post);
/*Checking response */
if(response!=null){
InputStream in = response.getEntity().getContent(); //Get the data in the entity
//System.out.println(response);
}
}
catch(Exception e){
e.printStackTrace();
System.out.println(e.toString());
//createDialog("Error", "Cannot Estabilish Connection");
}
}
}
);
請幫助我,我在JSON一個新手和Android.Thanx解析。
Thanx的答覆,請告訴我我是如何通過new_member =因爲我追加在網址,但實際提供的網址是http://www.fourerr.com/ws/signup我應該把新會員作爲JSON目的。??請幫助我.. – 2011-12-15 12:52:25