У меня есть массив Json, содержащий много информации. текст JSON содержит одинарные кавычки и двойные кавычки внутри. Я пытаюсь декодировать этот JSON в массив из-за одиночных и двойных кавычек в json.
это означает, что мне нужно разместить «вне моего JSON», чтобы он мог кодировать, но я не могу это сделать, или, может быть, моя логика ошибочна. может ли кто-нибудь помочь мне попробовать декодировать длинный список json, подобный этому, пожалуйста?
Я знаю, что haveto использовать json_decode ('{my json info}'); но у меня проблемы с размещением этих котировок
$b= {"articles": [ { "content": "THE Queen last night toasted the UK's \"special relationship\" with the US \u2013 and told Barack Obama how their two nations are keeping the world safe.\\n\\nAt a state banquet held for the US President at Buckingham Palace last night, she thanked America for twice coming to the rescue of the \"free world\" in two world wars.\\n\\nShe said: \"Your visit to this country inevitably reminds us of our shared history, our common language, and our strong intellectual and cultural links.\\n\\n\"It also reminds us that your country twice came to the rescue of the free and democratic world when it was facing military disaster.\\n\\n\"On each occasion, after the end of those destructive wars, the generosity of the United States made a massive contribution to our economic recovery. Today the United States remains our most important ally and our two nations contribute to the security and prosperity of our peoples, and of the world, through shared national interests.\"\\n\\nShe told the assembled VIP guests that when the two countries stand together \"our people and other people of goodwill around the world will be more secure and can become more prosperous\".\\n\\nThe Queen finished with a toast, saying: \"Ladies and gentlemen, we are here to celebrate the tried, tested and \u2013 yes \u2013 special relationship between our two countries.\"\\n\\nIn response, Mr Obama praised the nations' bond \u2013 and said it had never been stronger in the post-9/11 world.\\n\\nHe said: \"Our relationship never rested as we approach the 10th anniversary of 9/11. I am particularly grateful for the solidarity that the UK has shown in the last decade. From that day to this you have been our closest partner.\"\\n\\nMr Obama paid particular tribute to the UK's military help in Iraq and Afghanistan.\\n\\nHe said: \"You have been our closest partner in the struggle to protect our people from terror attacks and violent extremists around the world, despite heavy sacrifices. Allow me to pay tribute to the considerable sacrifices of your military forces who have stood shoulder to shoulder with us for decades as we together faced the challenges of the 21st century.\"\\n\\nHe finished with a toast, saying: \"Ladies and gentlemen stand with me and raise your glasses as I propose a toast to Her Majesty the Queen. To the vitality of the special relationship between our peoples and in the words of Shakespeare, 'To this blessed plot, this earth, this realm, this England'.\"\\n\\nThe 170 VIP guests included former prime ministers and diplomats as well as Hollywood royalty including Tom Hanks and Kevin Spacey.\\n\\nEarlier in the day, the first of their three-day visit to the UK, Mr Obama and First Lady Michelle were given a 41-gun salute by the Royal Artillery as they arrived at the Palace.\\n\\nAs gusts of wind circled all around, they were greeted by the Queen and Prince Philip. Even though the salute was half a mile away in Green Park, the Queen joked about the noise, shaking her head to clear her ears.\\n\\nThe Obamas also met the Duke and Duchess of Cambridge before being taken on a tour of the Buckingham Palace picture gallery, where Mr Obama was shown letters and artefacts charting Britain's loss of the American colonies.\\n\\nHe peered over to look at a handwritten manuscript by George III from 1783 in which the King proclaimed: \"America is lost.\"\\n\\nMr Obama joked: \"That was only a temporary blip in the relationship.\"\\n\\nHe was then shown a photo of HMS Resolute, timbers from which have been recycled for use in the White House. \"This is now my desk in the Oval Office,\" he said. \"I think we got a pretty good deal out of that.\"\\n\\nSecurity for the presidential visit is ultra-tight \u2013 and even while they're staying at Buckingham Palace the Obamas are taking no chances.\\n\\nThey have brought their own bomb- and bullet-proof windows \u2013 installed in the Belgian Suite at the Palace.\\n\\nIn a packed day, Mr Obama also met David Cameron at Downing Street before they visited a South London school.", "title": "The Queen toasts Barack Obama and special relationship with the US", "source_url": "http://www.mirror.co.uk/news/top-stories/2011/05/25/the-queen-toasts-barack-obama-s-special-relationship-115875-23154933/", "author": "Don Mackay", "published": "25/05/2011" } };
Вы пропустили последнее ]
<?php $json =<<<A {"articles": [ { "content": "THE Queen last night toasted the UK's \"special relationship\" with the US \u2013 and told Barack Obama how their two nations are keeping the world safe.\\n\\nAt a state banquet held for the US President at Buckingham Palace last night, she thanked America for twice coming to the rescue of the \"free world\" in two world wars.\\n\\nShe said: \"Your visit to this country inevitably reminds us of our shared history, our common language, and our strong intellectual and cultural links.\\n\\n\"It also reminds us that your country twice came to the rescue of the free and democratic world when it was facing military disaster.\\n\\n\"On each occasion, after the end of those destructive wars, the generosity of the United States made a massive contribution to our economic recovery. Today the United States remains our most important ally and our two nations contribute to the security and prosperity of our peoples, and of the world, through shared national interests.\"\\n\\nShe told the assembled VIP guests that when the two countries stand together \"our people and other people of goodwill around the world will be more secure and can become more prosperous\".\\n\\nThe Queen finished with a toast, saying: \"Ladies and gentlemen, we are here to celebrate the tried, tested and \u2013 yes \u2013 special relationship between our two countries.\"\\n\\nIn response, Mr Obama praised the nations' bond \u2013 and said it had never been stronger in the post-9/11 world.\\n\\nHe said: \"Our relationship never rested as we approach the 10th anniversary of 9/11. I am particularly grateful for the solidarity that the UK has shown in the last decade. From that day to this you have been our closest partner.\"\\n\\nMr Obama paid particular tribute to the UK's military help in Iraq and Afghanistan.\\n\\nHe said: \"You have been our closest partner in the struggle to protect our people from terror attacks and violent extremists around the world, despite heavy sacrifices. Allow me to pay tribute to the considerable sacrifices of your military forces who have stood shoulder to shoulder with us for decades as we together faced the challenges of the 21st century.\"\\n\\nHe finished with a toast, saying: \"Ladies and gentlemen stand with me and raise your glasses as I propose a toast to Her Majesty the Queen. To the vitality of the special relationship between our peoples and in the words of Shakespeare, 'To this blessed plot, this earth, this realm, this England'.\"\\n\\nThe 170 VIP guests included former prime ministers and diplomats as well as Hollywood royalty including Tom Hanks and Kevin Spacey.\\n\\nEarlier in the day, the first of their three-day visit to the UK, Mr Obama and First Lady Michelle were given a 41-gun salute by the Royal Artillery as they arrived at the Palace.\\n\\nAs gusts of wind circled all around, they were greeted by the Queen and Prince Philip. Even though the salute was half a mile away in Green Park, the Queen joked about the noise, shaking her head to clear her ears.\\n\\nThe Obamas also met the Duke and Duchess of Cambridge before being taken on a tour of the Buckingham Palace picture gallery, where Mr Obama was shown letters and artefacts charting Britain's loss of the American colonies.\\n\\nHe peered over to look at a handwritten manuscript by George III from 1783 in which the King proclaimed: \"America is lost.\"\\n\\nMr Obama joked: \"That was only a temporary blip in the relationship.\"\\n\\nHe was then shown a photo of HMS Resolute, timbers from which have been recycled for use in the White House. \"This is now my desk in the Oval Office,\" he said. \"I think we got a pretty good deal out of that.\"\\n\\nSecurity for the presidential visit is ultra-tight \u2013 and even while they're staying at Buckingham Palace the Obamas are taking no chances.\\n\\nThey have brought their own bomb- and bullet-proof windows \u2013 installed in the Belgian Suite at the Palace.\\n\\nIn a packed day, Mr Obama also met David Cameron at Downing Street before they visited a South London school.", "title": "The Queen toasts Barack Obama and special relationship with the US", "source_url": "http://www.mirror.co.uk/news/top-stories/2011/05/25/the-queen-toasts-barack-obama-s-special-relationship-115875-23154933/", "author": "Don Mackay", "published": "25/05/2011" }] } A; echo '<pre>'; print_r(json_decode($json, true)); ?>
По моему опыту, вам никогда не придется суетиться с кавычками при работе с json_decode
.
Я рекомендую попробовать json_decode( $b );
Если это не работает, то ваш «json» на самом деле не является действительным application/json
data, поэтому декодирование не выполняется.
$b = <<<JSON {"articles": [ { "content": ... ... JSON;
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc