Hello there,

I have a JSON Array variable which I retrieve with my php from Android platform:

$JSONkeyword = $_POST['keyword']

;

What I want is to use ''assert'' as I was advised, but I don't know how to do it.
My goal is that if that 'keyword' received from POST method is a String or an out of format array of strings ( because I want to try and POST this values from a HTML also), it converts to an array that recognizes and performs this code:

$keyword = json_decode($JSONkeyword,*true);

And if the file is already an array of strings it just performs that piece of code without going through any transformation.

Can someone help me?

    Currently I get this message when I try to POST from a HTML form.

    Warning: json_decode() expects parameter 1 to be string, array given in /home/pedrotei/public_html/thennnow/UT2.php on line 16

    Basiclly, I want to make it Generic, so I can post from HTML or the Android

      As Crowly says, use [man]is_array[/man] and [man]is_string[/man] to see what type of thing is in $_POST['keyword'], and then proceed from there as appropriate.

        Json values can be a string, a number, an object, an array, or the literals true, false, and null.
        But for the php json encoded value will be always a string, enclosed with code. So thats why json_decode accept only a string, so please check your post value, it should be string only for php. So I think you just append single quotes at beginning and at the end

          Write a Reply...