【发布时间】:2015-05-20 10:45:17
【问题描述】:
我有一个格式如下的 json 文件。我想修改该文件,以便向其中添加另一个键值对。键应为url,值应为www.mywebsite.co.nz,从下面给出的消息中提取。最简单的方法是什么?
{"
Timestamp":"Mon Mar 16 21:37:22 EDT 2015","Event":"Reporting Time","Message":"load for http://xxx.xx.xx.xx:1xxxx/operations&proxy=www.mywebsite.co.nz&send=https://xxx.xx.xx.xx:xxxx/operations?event took 9426 ms (X Time: 306 ms, Y Time: 1923 ms)
StatusCode: Unknown<br>Cookies: nzh_weatherlocation=12; dax_ppv=11|NZH:home|NZH:home|NZH:home|9|undefined; _ga=GA1.4.1415798036.1426208630; _gat=1<br>Links: 225<br>Images: 24<br>Forms: 10<br>Browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/41.0.2272.76 Chrome/41.0.2272.76 Safari/537.36<br>CPUs: 2<br>Language: en-GB","UserInfo":"Reporting Time"}
【问题讨论】:
-
在结尾
}前加,"url":"www.mywebsite.co.nz"?我在这里错过了什么吗? -
:) 我知道。我有大量文件要处理。我不能手动完成。我想通过某种方式使其自动化
-
为什么不使用像 PHP 或 Python 这样具有内置 JSON 读/写能力的语言?
-
我可以用python。虽然不是很熟悉
-
在 PHP 中它只是
$content = file_get_contents('path.json'); $json = json_decode($content); $json->url = 'www.mywebsite.co.nz'; $content = json_encode($content); file_put_contents('path.json', $content);