Arman Elm Arman Elm - 6 months ago 20
JSON Question

PHP - Escaping doesn't work for me?

I've been trying to do JSON in string, but I have to escape double quotes.. Here's the line

{\"assetid":".$assetid.", "floatvalue\":".$floatvalue.\"},

Answer

$data =
[
    'assetid'       => $assetid,
    'floatvalue'    => $floatvalue,
];

$result = json_encode( $data );

EDITED

foreach($floatdone['result']['items'] as $data)
{
    $assetid = $data['id'];
    $floatvalue = $data['attributes']['2']['float_value'];

    $swag[] = //YOUR MISTAKE, i guess, use $swag[] instead of $swag
    [
        'assetid'       => $assetid,
        'floatvalue'    => $floatvalue,
    ];
}

var_dump( json_encode($swag) );
Comments