title: How to get JSON objects from Nodejs server to Android client?
body: <p>I try to send JSON Object from Node.JS server to Android client.</p>
  <p>As I look at Stack Overflow, getting JSON object codes are below.</p>
  <pre><code>   new AsyncTask&lt;Void, Void, String&gt;() {
              @Override
              protected String doInBackground(Void... params) {
                  String msg = &quot;&quot;;
                  
                  DefaultHttpClient httpclient = new DefaultHttpClient();
  
                  HttpPost httpPost = new HttpPost(&quot;http://172.123.321123:52273/get&quot;);
                  httpPost.setHeader(&quot;Content-type&quot;, &quot;application/json&quot;);
  
                  ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
                  nameValuePairs.add(new BasicNameValuePair(&quot;mynum&quot;, &quot;1234&quot;));
                  try {
                      httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  } catch (UnsupportedEncodingException e1) {
                      // TODO Auto-generated catch block
                      Log.v(&quot;UnsupportedEncodingException&quot;,&quot;UnsupportedEncodingException&quot;);
                      e1.printStackTrace();
                  }
  
                  try {  
                      HttpResponse response = httpclient.execute(httpPost);
  
                      HttpEntity entity = response.getEntity();
  
                      InputStream is = entity.getContent();
  
                      BufferedReader reader = new BufferedReader(new InputStreamReader(is, &quot;UTF-8&quot;));
  
                      StringBuilder sb = new StringBuilder();
  
                      String line = null;
  
                      while ((line = reader.readLine()) != null) {
                          sb.append(line+&quot;\n&quot;);
                      }
                      is.close();
                      msg = sb.toString();
                      yourregID=msg;
  
                      JSONObject jsonResult = new JSONObject(msg);
  
                      String a = jsonResult.getString(&quot;myregID&quot;);
  
                      String b = jsonResult.getString(&quot;yourregID&quot;);
  
  
                  } catch (ClientProtocolException e) {
                      Log.v(&quot;ClientProtocolException&quot;, &quot;ClientProtocolException&quot;);
  
                      e.printStackTrace();
                      // TODO Auto-generated catch block
                  } catch (IOException e) {
                      Log.v(&quot;IOException&quot;, &quot;IOException&quot;);
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  } catch (JSONException e) {
                      // TODO Auto-generated catch block
                      Log.v(&quot;JSONException&quot;, &quot;JSONException&quot;);
  
                      e.printStackTrace();
                  }
                  return msg;
              }
  </code></pre>
  <p>and my Node.JS server codes are below:</p>
  <pre><code>  app.post('/get',function(request,response){
    var p_mynum=request.param('mynum');
    client.query('select ~',function(error,result){
    if(error){console.log('error
    ');}
    else{response.json(result);}});
  </code></pre>
  <p>I did postman and result is good. But in my Android device, it occurs:</p>
  <blockquote>
  <p>JSONException</p>
  <p>Error: invalid json<br> &amp; nbsp ; &amp; nbsp;at parase ~</p>
  </blockquote>
  <p>My JSON Object is long string.</p>