Reputation: 1352
I want to send string array to php by Json and retrieve there.
String[] Books = {"book1", "book2", "book3", "book4",..};
In Json:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>;
nameValuePairs.add(new BasicNameValuePair("books", Books));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
...
In php side:
$books = $_POST['books'];
$result = json_decode($books); // is this OK?
Or Can I use it like below?
$book1 = $result[0];
Upvotes: 2
Views: 922
Reputation: 2783
$jsonString = '["[email protected]","[email protected]","[email protected]"]';
$arrayOfYourEmails=json_decode($jsonString);
Or
$jsonString = "[\"[email protected]\",\"[email protected]\",\"[email protected]\"]";
$arrayOfYourEmails=json_decode($jsonString);
and yes your this code is right
$books = $_POST['books'];
$result = json_decode($books);
Upvotes: 1