android username password send through json to php-->sql -


I am trying to find a way to use json instead of normal http post to user name and password which is current I'm going to the United States through most tutorials and examples, but I'm still unable to get an idea. I have JSN Fasar to get data from my SQL, but Post Jason does not.

Thank you for your help

The JSON Post currently used in the

  edit text uname = (EditText) findViewById (R. Id.log_Eu_name); String Username = uname.getText (). ToString (); EditText pword = (edit text) findViewById (R.id.log_Epass); String password = pword.getText (). ToString (); String result = new string (); Results = ""; ArrayList & LT; NameValuePair & gt; NameValuePairs = New ArrayList & lt; NameValuePair & gt; (); NameValuePairs.add (New BasicNameValuePair ("username", user name)); NameValuePairs .add (New BasicNameValuePair ("password", password)); InputStream = Faucet; {HttpClient httpclient = Try New DefaultHttpClient (); Http post httppost = new HTTP post ("http://www.loshwickphotography.com/log.php"); Httppost.setEntity (new UrlEncodedFormEntity (nameValuePairs)); HttpResponse response = httpclient.execute (httppost); HttpEntity unit = response.getEntity (); Is = entity.getContent (); Logs. W ("Sensee," "execute HTTP post request"); String str = inputStreamToString (response.getEntity (.) GetContent ()). ToString (); Logs. W ("sediment", string); If (str.toString (.) Equal signalCase ("true")) {Log.w ("SENCIDE", "TRUE"); Toast. MakeApplicationContext (), "Hell Yeah!", Toast. LNNGHHORART). Show (); } Else {toast.makeText (getApplicationContext), "Sorry, this failed", toast .LENGTH_SHORT). Show (); }} Hold (exception e) {Log.e ("log_tag", "error in http connection" + e.toString ()); } {BufferedReader Reader = Try New BufferedReader (New InputStreamReader (iso-8859-1 "), 8); Stringbilder sb = new stringbiller (); String line = null; While ((line = reader. Readline ())! = Null () {sb.append (row + "\ n"); } is close(); Result = sb.toString (); } Hold (exception e) {Log.e ("log_tag", "Error converting result" + e.toString ()); } Try {if (result! = Tap) {JSONArray jArray = new JSONArray (results); Logs. I ("log_tag", integer.stosting (jArray.length ())); For (int i = 0; i & lt; jArray.length (); i ++) {JSONObject json_data = jArray.getJSONObject (i); }} And {toast} Make Text (getApplicationContext (), "NULL", Toast. LNNGHHORT). Show (); }} Hold (JasonXEpisode E) {log (e. "Log_tag", "error parsing data" + e.trustin ()); }} Private Object InputStreamToString (InputStream) {// TODO Auto generated method stub string line = ""; StringBiller Total = New StringBuilder (); // InputStream Wrap a BufferedReader around BufferedReader = rd = New BufferedReader (New InputStreamReader); // Try to End till the end {{line = rd.readline ())! = Null) {total.append (line); }} Hold (IOException e) {e.printStackTrace (); } // return complete string return total; }});   

Is it right that I have written?

How to write PHP for this?

use it

  JSONObject myjson = new JSONObject (); Myjson.put ("user name", "some one"); Myjson.put ("password", "123");   

and string = new string intentity (myjson.toString ());

and httpPost.setEntity (to);

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -