I am having an issue where my json object array isn't passing the values. I know they are there, but I can't get them to pass into the variables in my android app.
The Java function to handle the JSONObject:/**
* Function to get all userlogs
**/
public JSONObject getUserLogs(String userid){
// userlogs JSONArray
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", getUserLogs_tag ));
params.add(new BasicNameValuePair("userid", userid));
JSONObject json = jsonParser.getJSONFromUrl(getAllUserLogs,params);
return json;
}
Here is the Java do in backgrond:
protected String doInBackground(String... args) {
//List<NameValuePair> params = new ArrayList<NameValuePair>();
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
HashMap<String,String> user = new HashMap<String, String>();
user = db.getUserDetails();
userid = user.get("uid");
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.getUserLogs(userid);
Log.d("All userlogs: ", json.toString());
// return json;
try {
if (json.getString(KEY_SUCCESS) != null) {
userlogs = json.getJSONArray(KEY_USERLOGS);
// looping through All Products
for (int i = 0; i < userlogs.length(); i++) {
JSONObject c = userlogs.getJSONObject(i);
// Storing each json item in variable
String userID = c.getString(KEY_USERID);
String medname = c.getString(KEY_MEDNAME);
String medtaken = c.getString(KEY_MEDTAKEN);
String tabsleft = c.getString(KEY_TABSLEFT);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(KEY_USERID, userid);
map.put(KEY_MEDNAME, medname);
map.put(KEY_MEDTAKEN, medtaken);
map.put(KEY_TABSLEFT, tabsleft);
// adding HashList to ArrayList
logList.add(map);
}
}
}
catch (JSONException e) {
e.printStackTrace();
}
return null;
}
Here is the results:
03-20 04:47:01.212: E/JSON(7034): {"tag":"getUserLogs","success":1,"error":0,"userlogs":[{"userlogs":{"userid":"3705","medname":"atorvastatin 20mg","medtaken":"2014-03-20 03:48:49","tabsleft":"30"}},{"userlogs":{"userid":"3705","medname":"atorvastatin 20mg","medtaken":"2014-03-20 03:55:54","tabsleft":"30"}}]}
03-20 04:47:01.212: D/All userlogs:(7034): {"error":0,"success":1,"userlogs":[{"userlogs":{"userid":"3705","medtaken":"2014-03-20 03:48:49","tabsleft":"30","medname":"atorvastatin 20mg"}},{"userlogs":{"userid":"3705","medtaken":"2014-03-20 03:55:54","tabsleft":"30","medname":"atorvastatin 20mg"}}],"tag":"getUserLogs"}
03-20 04:47:01.212: W/System.err(7034): org.json.JSONException: No value for userid
03-20 04:47:01.212: W/System.err(7034): at org.json.JSONObject.get(JSONObject.java:355)
03-20 04:47:01.212: W/System.err(7034): at org.json.JSONObject.getString(JSONObject.java:515)
03-20 04:47:01.212: W/System.err(7034): at com.jipe.medicationstation.UserlogListActivity$LoadAllLogs.doInBackground(UserlogListActivity.java:104)
03-20 04:47:01.212: W/System.err(7034): at com.jipe.medicationstation.UserlogListActivity$LoadAllLogs.doInBackground(UserlogListActivity.java:1)
03-20 04:47:01.212: W/System.err(7034): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-20 04:47:01.212: W/System.err(7034): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-20 04:47:01.212: W/System.err(7034): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-20 04:47:01.212: W/System.err(7034): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-20 04:47:01.212: W/System.err(7034): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-20 04:47:01.212: W/System.err(7034): at java.lang.Thread.run(Thread.java:841)
The PHP:
else if ($tag == 'getUserLogs') {
$userid = $_POST['userid'];
//Special case (normally conntections handled in functions/config or connect)
$link = new mysqli($host, getDBuser(), getDBpassword(), getDBname());
/* check connection */
if (mysqli_connect_errno()) {
$response["error"] = 1;
$response["error_msg"] = mysqli_connect_error();
echo json_encode($response);
}
$query = "SELECT * FROM userlog WHERE userid = '$userid'";
$result = mysqli_query($link, $query);
$row_cnt = mysqli_num_rows($result);
//If results, then
if( $row_cnt > 0){
$response["userlogs"] = array();
while($row = mysqli_fetch_array($result, MYSQLI_BOTH)){
$userlog = array();
$userlog["userlogs"]["userid"] = $row["userid"];
$userlog["userlogs"]["medname"] = $row["medname"];
$userlog["userlogs"]["medtaken"] = $row["medtaken"];
$userlog["userlogs"]["tabsleft"] = $row["tabsleft"];
array_push($response["userlogs"], $userlog);
}
$response["success"] = 1;
echo json_encode($response);
mysqli_close($link);
}
else {
// userlogs not found
// echo json with error = 1
$response["error"] = 1;
$response["error_msg"] = "No Userlogs found";
echo json_encode($response);
}
}
else {
$response["error"] = 3;
$response["error_msg"] = "JSON ERROR";
echo json_encode($response);
}
}
Any suggestions?
You have
"userlogs": [ // jsonarray userlogs
{ // json object node
"userlogs": { // json object userlogs
Then
userlogs = json.getJSONArray(KEY_USERLOGS); // fine
for (int i = 0; i < userlogs.length(); i++) {
JSONObject c = userlogs.getJSONObject(i);
But you have a JSONObject userlogs also
JSONObject userlogsobject = c.getJSONObject("userlogs");
String userID = userlogsobject.getString(KEY_USERID);
Related
I am inserting some values from my android login page to mysql database using php .
login.php
<?php
$con = mysql_connect("localhost","abc","xyz") or die(mysql_error());
mysql_select_db("sync",$con) or die(mysql_error());
$user_name = $_POST['user_name'];
$user_mobile_no = $_POST['user_mobile_no'];
$user_email_id = $_POST['user_email_id'];
$imei_no = $_POST['imei_no'];
$login_date = $_POST['login_date'];
$time = $_POST['time'];
$user_name = 'Navdeep';
$user_mobile_no = '12345678990';
$user_email_id = 'nav#gmail.com';
$imei_no = '1234567890';
$login_date = '24-12-2012';
$time = '01:01:01';
$result = mysql_query("INSERT INTO
login_details(user_name,user_mobile_no,user_email_id,
imei_no,login_date,time)
VALUES('$user_name','$user_mobile_no','$user_email_id',' $imei_no','$login_date','$time')");
if($result)
{
$response["success"] = 1;
$response["message"] = "User Details inserted successfully";
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "There was an error inserting user details";
echo json_encode($response);
}
mysql_close($con);
?>
When i use $_POST[''] values are getting inserted as blank , but when i hardcode the values it is getting inserted , need some help
Android code :
try{
JSONObject jsonObject = new JSONObject();
jsonObject.put("user_name",userName);
jsonObject.put("user_mobile_no",mobNo);
jsonObject.put("user_email_id",email);
jsonObject.put("imei_no",imeino);
jsonObject.put("login_date",date);
jsonObject.put("time",time);
JSONArray jsonArray = new JSONArray();
jsonArray.put(jsonObject);
String basicAuth = "Device " + new
String(Base64.encode((imeino).getBytes(), Base64.NO_WRAP));
RequestBody body =
RequestBody.create(JSON,String.valueOf(jsonArray));
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder().header("Authorization",
basicAuth).url(url).post(body).build();
Call call = okHttpClient.newCall(request);
call.enqueue(new Callback() {
#Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
Login.this.runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getBaseContext(), "Request to the
server failed", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public void onResponse(Call call, Response response) throws
IOException {
Log.i("response ", "onResponse(): " + response );
StatusLine statusLine = null;
String result = response.body().string();
if(result.equals("") || result.equals(null)){
Log.i("No response", "No response");
}else{
Log.i("Response","Response "+result);
statusLine = StatusLine.get(response);
final int responseCode = statusLine.code;
Log.d("Code:", String.valueOf(responseCode));
}
}
});
}catch (Exception e){
e.printStackTrace();
}
You should send form data request from android.
Replace this
JSONObject jsonObject = new JSONObject();
jsonObject.put("user_name",userName);
jsonObject.put("user_mobile_no",mobNo);
jsonObject.put("user_email_id",email);
jsonObject.put("imei_no",imeino);
jsonObject.put("login_date",date);
jsonObject.put("time",time);
JSONArray jsonArray = new JSONArray();
jsonArray.put(jsonObject);
String basicAuth = "Device " + new
String(Base64.encode((imeino).getBytes(), Base64.NO_WRAP));
RequestBody body =
RequestBody.create(JSON,String.valueOf(jsonArray));
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder().header("Authorization",
basicAuth).url(url).post(body).build();
With
RequestBody formBody = new FormBody.Builder()
.add("user_name",userName)
.add("user_mobile_no",mobNo)
.add("user_email_id",email)
.add("imei_no",imeino)
.add("login_date",date)
.add("time",time)
.build();
String basicAuth = "Device " + new
String(Base64.encode((imeino).getBytes(), Base64.NO_WRAP));
Request request = new Request.Builder().header("Authorization",
basicAuth).url(url).post(formBody).build();
I am trying to retrieve multiple rows of data. However, I am getting a error.
I want to retrieve rows of which the name (under the column name) = the name of the user. Which part of my code do I have to alter?
protected String doInBackground(String... args) {
// Building Parameters
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name", name));
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_coupons, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String couponexpires = c.getString(TAG_COUPONEXPIRES);
String coupondetails = c.getString(TAG_COUPONDETAILS);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_COUPONEXPIRES, couponexpires);
map.put(TAG_COUPONEXPIRES, coupondetails);
// adding HashList to ArrayList
couponsList.add(map);
My php code
<?php
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
if (isset($_GET["name"])) {
$name= $_GET['name'];
$result = mysql_query("SELECT * FROM coupons WHERE name = '$name'") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
$response["products"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["couponcreated"] = $row["couponcreated"];
$product["couponexpires"] = $row["couponexpires"];
$product["coupondetails"] = $row["coupondetails"];
array_push($response["products"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?>
My logcat
5202-5251/info.androidhive.loginandregistration E/JSON Parser﹕ Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
12-21 11:24:50.750 5202-5251/info.androidhive.loginandregistration W/dalvikvm﹕ threadid=11: thread exiting with uncaught exception (group=0x41b9f700)
12-21 11:24:50.755 5202-5251/info.androidhive.loginandregistration E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NullPointerException
at info.androidhive.loginandregistration.CouponPageActivity$LoadAllProducts.doInBackground(CouponPageActivity.java:103)
at info.androidhive.loginandregistration.CouponPageActivity$LoadAllProducts.doInBackground(CouponPageActivity.java:76)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
There is syntax error in script(if condition not closed). use below script:
<?php
// array for JSON response
$response = array();
$response["success"] = 0;
$response["message"] = "No products found";
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
if (isset($_GET["name"])) {
$name = $_GET['name'];
$result = mysql_query("SELECT * FROM coupons WHERE name = '$name'") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
$response["products"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["couponcreated"] = $row["couponcreated"];
$product["couponexpires"] = $row["couponexpires"];
$product["coupondetails"] = $row["coupondetails"];
array_push($response["products"], $product);
}
// success
$response["success"] = 1;
$response["message"] = '';
} else {
// no products found
// echo no users JSON
}
}
echo json_encode($response);
?>
I have an error as stated in the title when trying to read SQL and encode it back to android.
I have tried the following:
Verified the value of $androidIMEI by printing to log file, value is returned as expected.
Verified the output of $sql and the query is OK (including the $_POST['myIMEI_toString']) value from android.
Verified the value of $json array, 2 arrays are returned as the query returns 2 rows from SQL, OK.
Replacing
$androidIMEI = isset($_POST['myIMEI_toString']) ? $_POST['myIMEI_toString'] : '';
WITH
$androidIMEI = "000000000000000" //works fine but I want to get that programmatically.
Code:
Android (Send IMEI):
TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
myIMEI = mngr.getDeviceId();
myIMEI_toString = myIMEI.toString();
...............
protected String doInBackground(String... arg0) {
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("myIMEI_toString",myIMEI_toString));
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://path_on_server/file.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
InputStreamReader ireader = new InputStreamReader(is);
BufferedReader bf = new BufferedReader(ireader);
sb = new StringBuilder();
String line = null;
while ((line = bf.readLine()) != null) {
sb.append(line);
}
Log.e("pass 1", "connection success ");
}
catch(Exception e)
{
System.out.println("Error catch");
}
return id;
}
Android (JSON):
try {
JSONObject jsonResponse = new JSONObject(jsonResult);
JSONArray jsonMainNode = jsonResponse.optJSONArray("myarray");
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
name = jsonChildNode.getString("Request_Name");
number = jsonChildNode.getString("Request_Number");
username = jsonChildNode.getString("Request_Username");
status = jsonChildNode.getString("Status");
arrName.add(name);
arrNumber.add(number);
arrUsername.add(username);
arrStatus.add(status);
System.out.println("Name: "+name);
System.out.println("Number: "+number);
System.out.println("Username: "+username);
System.out.println("Status: "+status);
}
} catch (JSONException e) {
Log.i("Error Log: ", e.toString());
System.out.println("Error: "+e.toString());
Toast.makeText(getApplicationContext(), "Error" + e.toString(), Toast.LENGTH_SHORT).show();
}
PHP:
<?php
include 'config.php';
//$androidIMEI = "000000000000000";
$androidIMEI = isset($_POST['myIMEI_toString']) ? $_POST['myIMEI_toString'] : '';
//$f = fopen("log.txt", "w");
//fwrite($f, print_r($androidIMEI, true));
//fclose($f);
$con=mysql_connect("$servername", "$username", "$password")or die("cannot connect");
mysql_select_db("$dbname")or die("cannot select DB");
$sql = "SELECT * from users WHERE Request='0' AND IMEI = '$androidIMEI' ";
$result = mysql_query($sql);
$json = array();
if(mysql_num_rows($result)){
while($row=mysql_fetch_assoc($result)){
$json['myarray'][]=$row;
}
}
else
{
//$error = "Error selecting record: " . $conn->error " ";
//$f = fopen("$error.txt", "w");
//fwrite($f, print_r($error, true));
//fclose($f);
}
$f = fopen("log.txt", "w");
fwrite($f, print_r($sql, true));
fclose($f);
mysql_close($con);
echo json_encode($json);
?>
Logcat Error:
org.json.JSONException: Value [] of type org.json.JSONarray cannot be converted to JSONObject
(i have asked this question before but will try again with more information)
I have to send byte array using Http post method,but in basicnamevalue pair class its gives
me error as the constructor BasicNameValuePair(String, byte[]) is undefined.is any onother way to solved this issue please help me.
AsyncTask :
public void SaveDatandImage() {
Byte[] image1,image2;
new AsyncTask<Void, Void, String>() {
protected void onPreExecute() {
pDialog = new ProgressDialog(DetailsAcceptActivity.this);
pDialog.setTitle("Sending Query");
pDialog.setMessage("Please Wait...");
pDialog.setCancelable(true);
pDialog.show();
};
protected String doInBackground(Void... params) {
String response = null;
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
Date today = new Date();
nameValuePairs.add(new BasicNameValuePair("name","Name"));
nameValuePairs.add(new BasicNameValuePair("image1",image1));
nameValuePairs.add(new BasicNameValuePair("image2",image2));
if (Common.isInternetConnected(DetailsAcceptActivity.this)) {
try {
response = Common.httpPost(url_make_query, nameValuePairs, new String[] {});
// Jobj=jparser.makeHttpRequest(url_make_query, "POST", nameValuePairs);
Log.v(Common.TAG, "Record respose : " + response);
Intent intent = new Intent(DetailsAcceptActivity.this, LoginActivity.class);
DetailsAcceptActivity.this.finish();
startActivity(intent);
//Toast.makeText(MenuActivity.this,"Record Saved",Toast.LENGTH_SHORT).show();
/*JSONObject jObj = new JSONObject(response);
strRespCode = jObj.getString("success");
strRespMessage=jObj.getString("message");
int success=Jobj.getInt(TAG_SUCCESS);
if(success==1) {
Toast.makeText(MenuActivity.this,"inserted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MenuActivity.this,"Error", Toast.LENGTH_SHORT).show();
}*/
//if(response.e)
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
//groupMember.setSynced_with_server(StaticMembers.ZERO);
return "NO_NETWORK";
}
return response;
};
protected void onPostExecute(String result) {
if (result != null) {
if(!result.equals("NO_NETWORK")) {
//groupMember.setSynced_with_server(StaticMembers.ONE);
}
//Log.w("strRespMessage= "+strRespMessage, "********");
// Toast.makeText(MenuActivity.this, "Query Sent!!", Toast.LENGTH_LONG).show();
//finish();
}
pDialog.dismiss();
}
}.execute(null, null);
}
PHP Script to accept data from front end
<?php
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['sender_mobile_no'])) {
$name = $_POST['name'];
$image1= $_POST['image1'];
$image2= $_POST['image2'];
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
// mysql inserting a new row
$result = mysqli_query($con,"INSERT INTO tbl_query_master(name,image1,image2) VALUES('$name','$sender_name', '$image1', '$image2')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Order placed successfully.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
You can encode your image bytes into String and then send it on server. You can use
String strImage=Base64.encodeToString(image1, Base64.DEFAULT); // image1 is your byte[]
and then set this String in your namevaluepair as
nameValuePairs.add(new BasicNameValuePair("image1",strImage));
In php:
you can decode your string to get bytearray as follows.
$str=$_POST['image1'];
$abc=base64_decode($str);
I get following error:
Error parsing data org.json.JSONException: Value [] of type org.json.JSONArray cannot be converted to JSONObject
Here is the Android and PHP code I have:
private void eventUpdatePoint(String eventStatus,int lat,int lon){
JSONParser jsonParserEUP = new JSONParser();
try
{
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("longtitude", Integer.toString(lon)));
params.add(new BasicNameValuePair("latitude", Integer.toString(lat)));
params.add(new BasicNameValuePair("eventstatus", eventStatus));
String url_updatePoint = "http://10.0.2.2/android_connect/event_update_point.php";
JSONObject json = jsonParserEUP.makeHttpRequest(url_updatePoint,"POST", params);
Log.d("Response", json.toString());
}
catch(Exception e)
{
e.printStackTrace();
Log.d("ERROR:","ERROR:" + e.getClass().getName() + ":" + e.getMessage());
}
}
php code:
$response = array(); if (isset($_POST['longtitude']) && isset($_POST['latitude']) &&isset($_POST['eventstatus'])) {
$longtitude = $_POST['longtitude'];
$latitude = $_POST['latitude'];
$eventstatus = $_POST['eventstatus'];
$e_id=0;
$score=0;
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$result = mysql_query("SELECT id FROM cordinates WHERE longtitude=$longtitude AND latitude=$latitude") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$e_id = $row["id"];
}
$result = mysql_query("SELECT score FROM point WHERE e_id=$e_id") or die(mysql_error());
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
$score = $row["score"];
}
if($eventstatus=="inc")
{
$score+=10;
$result = mysql_query("UPDATE point SET score=$score where e_id=$e_id") or die(mysql_error());
$response["success"] = 1;
$response["message"] ="Score point increased";
}
else if($eventstatus=="dec")
{
$score-=10;
$result = mysql_query("UPDATE point SET score=$score where e_id=$e_id") or die(mysql_error());
$response["success"] = 0;
$response["message"] ="Score point decreased";
}
}
echo json_encode($response);
What am I doing wrong?
The webservice you are using returns a JSONArray. You have to use an object of type JSONArray to store it. You can't use a JSONObject.
Change this line:
JSONObject json = jsonParserEUP.makeHttpRequest(url_updatePoint,"POST", params);
...to this:
JSONArray json = jsonParserEUP.makeHttpRequest(url_updatePoint,"POST", params);
Log your response.If it starts with"[" and ends with "]",you have to store it in variable of type "JSONArray".With attention to your log,your response must be a "JSONArray",so simply save your response in a variable of type "JSONArray".