Can't replace block with a Command Block [duplicate]

I am making a Sell Shop, but I need to replace some things using /setblock.

For one of the replacements, I am using the command:

/setblock 579 62 1053 minecraft:command_block 0 replace {Command:"testfor @p {Inventory:[{id:"minecraft:log",Count:32b}]}",TrackOutput:0}

But it won't work! When I try it using a Command Block, I get this message:

[19:14:38]
Data tag parsing failed: Unexpected token 'm' at: minecraft:log",Count:32b}]}",TrackOutput:0

Is there any way I can fix this?


Solution 1:

The first quotation mark for the Command string that you wrote will open the string. The very next un-escaped quotation mark will then close that string, which happens after the id tag.

To prevent a quotation mark from closing the string early, you must escape the character by applying a backslash before it.

/setblock 579 62 1053 minecraft:command_block 0 replace {Command:"testfor @p {Inventory:[{id:\"minecraft:log\",Count:32b}]}",TrackOutput:0}