title: How to make a "raw" string out of JSON in Java
body: <p>I am coding an android app for school atm. i am stock and want to ask you guy to help me.
  So far i understand how to use PHP to print data from a MySQL database ready to be parset in Java. Then my code(taken from here: <a href="http://www.helloandroid.com/tutorials/connecting-mysql-database)takes" rel="nofollow">http://www.helloandroid.com/tutorials/connecting-mysql-database)takes</a> the data and converts it into strings i believe.</p>
  
  <p>So my question is: how do i for eksample make and if statement to check if the userdata is correct? i just dont get it!</p>
  
  <p>Here is all my code for the activity(login form) i use:</p>
  
  <pre><code>package com.example.fungi;
  
  
  import java.io.BufferedReader;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicNameValuePair;
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.app.ActionBar;
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  
  
  
  public class MainActivity extends Activity {
  //Intent i = new Intent(getBaseContext(), MainPageActivity.class);                      
  //startActivity(i);
  Button login;
  EditText username;
  EditText password;
  TextView lol;
  JSONArray jArray;
  String result = null;
  InputStream is = null;
  StringBuilder sb=null;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      //ActionBar actionBar = getActionBar();
      //actionBar.hide();
      lol = (TextView) findViewById(R.id.textView1);
      login = (Button) findViewById(R.id.loginbutton);
      username = (EditText) findViewById(R.id.usernametext);
      password = (EditText) findViewById(R.id.passwordtext);
      login.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              String usernameget = username.getText().toString();
              String passwordget = password.getText().toString();
  
              if(usernameget.contentEquals("")){
                  username.setText("usernam required");
              }else {
                  if(passwordget.contentEquals("")){
                      username.setText("password required");
                  }else {
                      String userid = username.getText().toString();
                      Intent intent = new Intent(getBaseContext(), Side.class);
                      intent.putExtra("sessionid", userid);
                      startActivity(intent);
  
                      }
  
              }
  
          }
  
      });
      String result = "";
      //the year data to send
      ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
      nameValuePairs.add(new BasicNameValuePair(result, result));
  
      //http post
      try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://http://fungi.webatu.com/Index.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
        }catch(Exception e11){
        Log.e("log_tag", "Fejl i HTTP connection "+e11.toString());
        }
  
      //convert response to string
      try{
  
          BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
            }
            is.close();
  
            result=sb.toString();
      }catch(Exception e){
            Log.e("log_tag", "Fejl i resultat konvertering "+e.toString());
      }
  
      //parse json data
      try{
            JSONArray jArray = new JSONArray(result);
            for(int i=0;i&lt;jArray.length();i++){
                    JSONObject json_data = jArray.getJSONObject(i);
                    Log.i("log_tag","id: "+json_data.getInt("id")+
                            ", username: "+json_data.getString("username")+
                           ", password: "+json_data.getString("password")+
                            ", alder: "+json_data.getInt("alder"));
  
  
                  //maybe if statement here?
  
  
                    ;
            }
  
      } 
      catch(JSONException e1){
            Log.e("log_tag", "Error parsing data "+e1.toString());
      }
  
  
  }
  
  
  
  }
  </code></pre>
  
  <p>thanks in advance!!</p>