3
I have the following JSON that came from a Javascript and I’m using it in PHP. I’m giving json_decode($json)
, but obviously it doesn’t work. Because there are no quotes in the index of every value.
options: [
{
value: "120",
id: "40",
title: "1400g",
name: "Tamanho"
},
{
value: "336",
id: "60",
title: "Chocolate",
name: "Sabor"
}
]
How can I fix this in PHP?
How does this JSON get to PHP? Ideally it would be for the sender, not the sender. If you’re sending it by Javascript, a
JSON.stringify
should generate a valid JSON.– Andre
I am reading the DOM of a product page and the JSON is inside a javascript that is used on the page, I have no way to choose how I will receive unfortunately
– VitorZF
Did it work Vitor? If it worked the answer. Put it as right. I advise you to choose the answer of Lipespry. ✔
– Andrei Coelho
Take a look at syntax of JSON to see that what you have is at most an incomplete piece of a JSON. Maybe you should take a step back and rethink whether this is the best solution for whatever you’re trying to do, because taking an incomplete chunk of Javascript and trying to interpret in PHP doesn’t seem like a good approach.
– hkotsubo
It is really a piece of json, after all json has more than 1000 positions so there is not much to post here, I will test the Lipespry and already produce the upvote if it works
– VitorZF