如何从PHP写入时从JSON文件中删除引用? [英] How to remove quotations from JSON file while writing from PHP?
本文介绍了如何从PHP写入时从JSON文件中删除引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有以下代码,它有一个数组,并将其输出到名为'example.json'的JSON文件中。
以下是输出的代码:
I currently have the following code which has an array, and outputs it into a JSON file called 'example.json'.
Below is the code that outputs to it:
$x = array(1, 2, 3); //Defining two basic arrays
$y = array(2, 4, 6);
$name = array("Joe", "John", "Johnny");
echo count($x);
$objOne = '["type": "FeatureCollection", "features": [';
file_put_contents("jsonfun.json", json_encode($objOne));
for($i = 0; $i < count($x); $i++)
{
$objTwo = '{ "type": "Feature", "geometry": {"type": "Point", "coordinates": [' . $x[$i] . ', ' . $y[$i] . ']}, "properties": {"name": ' . $name[$i] . '} }]';
file_put_contents("jsonfun.json", json_encode($objTwo), FILE_APPEND);
}
$objThree = '};';
file_put_contents("jsonfun.json", json_encode($objThree), FILE_APPEND);
Output:
"[\"type\": \"FeatureCollection\", \"features\": [""{ \"type\": \"Feature\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [1, 2]}, \"properties\": {\"name\": Joe} }]""{ \"type\": \"Feature\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [2, 4]}, \"properties\": {\"name\": John} }]""{ \"type\": \"Feature\", \"geometry\": {\"type\": \"Point\", \"coordinates\": [3, 6]}, \"properties\": {\"name\": Johnny} }]""};"
你可能已经看到有很多斜线我不喜欢我们不知道他们来自哪里......同样也有几个不应该引用的引用;
例如。
As you may have seen there are a lot of slashes which I don't know where they came from... and likewise there are also several quotations where they shouldn't be;
eg.
"[type...
我有没有机会删除那些,或者我在做什么这不对吗?
我的尝试:
我研究过进入它,但无法找到任何东西......
Is there any chance I could remove those, or am I doing it wrong?
What I have tried:
I have researched into it but wasn't able to find anything...
推荐答案
x =数组(1,2,3); // 定义两个基本数组
x = array(1, 2, 3); //Defining two basic arrays
>
y = array(2,4,6);
y = array(2, 4, 6);
name = array( Joe, < span class =code-string> John, Johnny);
echo count(
name = array("Joe", "John", "Johnny"); echo count(
这篇关于如何从PHP写入时从JSON文件中删除引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文