【发布时间】:2014-10-15 17:25:14
【问题描述】:
我有一个名为“jason_file.json”的 JSON 文件,如下所示:
[
{"name":"name1", "city":"city1", "country":"country1"},
{"name":"name2", "city":"city2", "country":"country2"},
{"name":"name3", "city":"city3", "country":"country3"},
{"name":"name4", "city":"city4", "country":"country4"},
{"name":"name5", "city":"city5", "country":"country5"}
]
使用 for 循环,我想从文件中删除前两个对象,并将剩余的对象以相同的顺序保存在“jason_file.json”中。要求的结果应该是:
[
{"name":"name3", "city":"city3", "country":"country3"},
{"name":"name4", "city":"city4", "country":"country4"},
{"name":"name5", "city":"city5", "country":"country5"}
]
我该怎么做?
【问题讨论】:
-
我会使用
file_get_contents、file_put_contents、json_decode、json_encode和一些unset。你能自己试一试吗?这是很好的做法。