2011-12-16 3 views
0

코드에서 웹 서비스에 데이터를 게시하고 있지만 웹 서비스에서 응답하는 것은 지정된 데이터가 비어 있다는 것입니다. 이는 내 요청이 webservice하지만 해당 키 값을 가져올 수 없습니다.Android : JSON을 사용하여 웹 서비스에 데이터 게시

코드 :

Button b1=(Button)findViewById(R.id.button1); 
     b1.setOnClickListener(new OnClickListener() 
     { 

      public void onClick(View v) { 
       String gaurav ="new_member="+"[{\"email\":\"[email protected]\",\"username\":\"gaurav001\",\"pwd\":\"gaurav001\"}]"; 
       // TODO Auto-generated method stub 
       HttpClient httpclient = new DefaultHttpClient(); 
       HttpPost httppost = new HttpPost("url"); 

try{ 
    String d="[email protected]"; 
        JSONObject json = new JSONObject(); 

        json.put("gaurav", gaurav); 
        // json.put("api_token",settings.getString("api_token", "")); 
        StringEntity se = new StringEntity(json.toString()); 
        httppost.setEntity(se); 
        httppost.setHeader("Accept", "application/json"); 
        httppost.setHeader("Content-type", "application/json"); 
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); 


        HttpResponse response = httpclient.execute(httppost); 
        HttpEntity responseEntity =response.getEntity(); 

        Log.e("USER", EntityUtils.toString(responseEntity).trim()); 
} catch (UnsupportedEncodingException e11) { 
        // TODO Auto-generated catch block 
        Log.e("USER", e11.getMessage()); 
       } catch (ClientProtocolException e11) { 
        // TODO Auto-generated catch block 
        Log.e("USER", e11.getMessage()); 
       } catch (IOException e11) { 
        // TODO Auto-generated catch block 
        Log.e("USER", e11.getMessage()); 
       } catch (JSONException e11) { 
        // TODO Auto-generated catch block 
        e11.printStackTrace(); 
       } 

      } 

     } 
       ); 

서버의 응답은 다음과 같습니다 서버에서 응답

12-16 13:59:47.542: E/USER(1257): [{"errorcode":"012"}] 

목록 :

012 You must enter your e-mail address 
013 You must enter your username 
014 The username you chose is already taken 
015 Your e-mail address is invalid 
016 The e-mail address you entered is already taken 
017 You must enter a password 
025 Your username should have at least 4 characters 
024 Username can only contain letters A-Z and numbers 0-9 

나는 모두가 잘가는 느낌을 얻고있다 , 그리고 그 중 하나가 내 문자열 gaurav; 문자 그대로 문제입니다. 그녀는 내가 웹 서비스 스펙에 따라 전달해야하는 문자열입니다.

new_member = [{ "이메일": "[email protected]", "사용자 이름": "gaurav001", "pwd": "gaurav001"}]

여러 번 시도했지만 오류 코드가 여전히 12 번입니다.

답변

2

내가 뭐하는 거지 것은

JSONObject jsonObject = new JSONObject(); 
jsonObject.put("email", "[email protected]"); 
jsonObject.put("uname", "test"); 
jsonObject.put("upwd", "test123"); 

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

List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); 
nameValuePair.add(new BasicNameValuePair("bulkdata",jArrayParam.toString())); 

HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httppost = new HttpPost(url); 
httppost.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); 

// Execute HTTP Post Request 
HttpResponse response = httpclient.execute(httppost); 

는 ... 서버 측에서

을이 값을 얻을 수 있습니다 bulkdata를 사용하여, 같은 것입니다
관련 문제