擅长:python、mysql、java
<p>使用<a href="http://docs.python.org/2/library/json.html" rel="nofollow">json</a>模块将字符串转换为一组嵌套的<code>dict</code>对象,进行更改,然后将字典转储回json字符串。在</p>
<pre><code>import json
jstr = '''{
"EZMessage":{
"action":"account.cash",
"data":{
"authToken":"123456",
"account":"#ACCOUNTID#",
"portfolio":"true",
"historical":"true"
}
}
}'''
j = json.loads(jstr)
j['EZMessage']['data']['authToken'] = 654321
jstr = json.dumps(j)
</code></pre>
<p>有关如何读/写文件的信息,请参阅<a href="http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files" rel="nofollow">the fine tutorial</a>。在</p>