Prevent quoting of certain values with PHP json_encode()

后端 未结 7 1395
广开言路
广开言路 2021-01-06 01:21

When using PHP\'s json_encode to encode an array as a JSON string, is there any way at all to prevent the function from quoting specific values in the returned string? The r

相关标签:
7条回答
  • 2021-01-06 01:59

    my quickfix was this:

    $myobject->withquotes = 'mystring';
    $myobject->withoutquotes = '##noquote## mystring ##noquote##';
    

    and later

    str_replace(array('"##noquote## ', ' ##noquote##"'), '', json_encode($myobject))
    

    result is something like this

    {"withquotes":"mystring","withoutquotes":mystring}
    
    0 讨论(0)
提交回复
热议问题