Reputation: 2274
I am sending through some values from android/java to a server.
First I create a JSONArray object:
JSONArray JSONsamples = new JSONArray();
then I populate the JSONArray the following way:
for(.....)
{
if(...)
{
JSONsamples.put(storedArraylist.get(i));
}
}
Then I send the value through post :
userParameters.add(new BasicNameValuePair("samples", JSONsamples.toString()));
.
.
Http_Client.executeHttpPost(getApplicationContext(), POST_url, userParameters);
.
Then on the server I try to store those values into a php array, but it does not work:
$samplesarray = $_POST["samples"];
$samplesarray = json_decode($samplesarray,true);
Before decoding, If I echo $samplesarray , I only get the first value encapsulated in these \"value\" , after json_decode , when I echo $samplesarray I get a parameter expected but null found error.
Please help.
Upvotes: 1
Views: 155
Reputation: 2274
The solution is removing magic quotes, or at least checking if its on or not and working from there. @steven reminded me of this, thank you.
So on the server side, I do the following check to ensure correct json and it works :
$samplesarray = get_magic_quotes_gpc() ? stripslashes($_REQUEST['samples']) : $_REQUEST['samples'];
Upvotes: 0
Reputation: 4875
Magic Quotes should be turned off because it adds a \
before your "
values.
This breakes the json data in your case.
Please read more about why you should not use magicquotes here: http://php.net/manual/en/security.magicquotes.whynot.php
Upvotes: 1