试图从我的json中找到并摆脱这个\ u0000

This is my $var from json_encode:

{
"key1":"\u0000data1",
"key2":"\u0000data2",
"key3":"\u0000data3",
"key4":"\u0000data4
}

I would like to do this:

echo json_encode(str_replace ("\\u0000", "",  $var));

in order to get rid of the preceding \u0000 that's showing up, the line above doesn't work to strip it.

You'll have to apply the function the other way round:

echo str_replace('\\u0000', '', json_encode($var));

This is because $var is an array. You'd have to iterate over all its entries and look for the \0 byte otherwise.

I ran into something similar.

This question & answer helped me understand the route cause of the problem.

I overcame this by realising that my class properties (equivalent to each keyn in your question) didn't really need to be protected. By making them public I side-stepped the issue altogether.

I suppose it's up to you to decide if this is best practice or suited to your project however.