Loop through JSON Array Loop through JSON Array json json

Loop through JSON Array


json_decode() doesn't return an array. To get it to do so you'd need to do json_decode($_REQUEST['names'], true)

http://php.net/manual/en/function.json-decode.php


There seems to be something strange going on when using:

{names : JSON.stringify(fullName)}

As you are sending key - value pairs using GET or POST, you probably need to encode the value correctly.

You could do that using:

{names : encodeURIComponent(JSON.stringify(fullName))}


EDIT: jQuery is being insane again.

$.getJSON("names.php?names=" + encodeURIComponent(JSON.stringify(fullName)), function(data)        {                for(var i = 0; i < data.test.length; i++)                {                        window.alert(data.test[i]);                }        });

The problem was it was adding each item in the array as seperate value to URI.