views:

59

answers:

4
Array
(
    [sEcho] => 1
    [iTotalRecords] => 7521
    [iTotalDisplayRecords] => 1
    [aaData] => Array
        (
            [0] => Array
                (
                    [0] => Nordic Capital Buys SiC Processing
                    [1] => 2010-06-21/nordic-capital-buys-sic-processing
                    [2] => PEHub Media
                    [3] => Business
                    [4] => completed
                    [5] => Nordic Capital has acquired a 70% stake in SiC Processing AG, a German industrial recycling company, from Frog Capital. No sale price was disclosed.  SiC Processing’s founding family retains a 25% holding, while former lead investor Zouk Ventures retains a 5% stake.

                    [6] => Admin, China, Frog Capital, Germany, Italy, Iyad Omari, Manufacturing, Norway, PEHub Media, Photovoltaic Wafer Manufacturing, Renewable Energy, Semiconductor, United States
                )

        )

)

echo json_encode($myArr);

{"sEcho":"1","iTotalRecords":7521,"iTotalDisplayRecords":"1","aaData":[[" Nordic Capital Buys SiC Processing<\/a><\/div>"," 2010-06-21\/nordic-capital-buys-sic-processing<\/div>","PEHub Media","Business","completed",null," Admin, China, Frog Capital, Germany, Italy, Iyad Omari, Manufacturing, Norway, PEHub Media, Photovoltaic Wafer Manufacturing, Renewable Energy, Semiconductor, United States]]}

Note the null in the middle of the string after completed

Why is this, what escape/manipulation do I need to perform in order to encode this?

I have tried, addslashes

+1  A: 

I just tried that exact same code, and it returned the following:

{"var1":"test string","var2":"Nordic Capital has acquired a 70% stake in SiC Processing AG, a German industrial recycling company, from Frog Capital. No sale price was disclosed.  SiC Processing\u2019s founding family retains a 25% holding, while former lead investor Zouk Ventures retains a 5% stake.","var3":"test string 3"}

What version of PHP are you running? And is this from your localhost or you running this on a remote box?

xil3
Please check my question again i have updated with full code, as json_encode is working with rest of array.
Lizard
So, it looks like a problem with the 5th element in the array. Can I see the code for the generation of the array?
xil3
its just a field from a database
Lizard
+1  A: 

Actually it doesn't return null, http://codepad.org/A34KdUf5.

Maybe your PHP version doesn't support json_encode().

Luca Matteis
Please check my question again i have updated with full code, as json_encode is working with rest of array.
Lizard
+1  A: 

Works for me on 5.2.13. Ensure you're using at least PHP 5.2.0 and that PHP wasn't compiled with --disable-json. You may also want to check that error reporting (and/or logging) is enabled.

AllenJB
Please check my question again i have updated with full code, as json_encode is working with rest of array.
Lizard
+1  A: 

From the manual:

Note that if you try to encode an array containing non-utf values, you'll get null values in the resulting JSON string. You can batch-encode all the elements of an array with the array_map function:

$encodedArray = array_map(utf8_encode, $myArr);
echo json_encode($encodedArray);
seengee
Thanks knob jockey, I will test it out. :D
Lizard
That worked... Now stop voting me down!
Lizard
eh? i haven't been. check my profile i've done 5 down votes in total!
seengee
i checked that and you're right! congratulations
Luca Matteis