2019-05-29 10:27:39 4709瀏覽
對Python開發(fā)技術感興趣的小伙伴多數(shù)都會參加專業(yè)的Python培訓學習,本篇文章小編給讀者們分享一下在Python中將字符串轉為json對象并取值的方法,感興趣的小伙伴就隨小編來了解一下吧,希望對小伙伴們有幫助。
如下所示:
string =" { "status": "error", "messages": ["Could not find resource or operation 'BZK1.MapServer' on the system."], "code": 404 }"
print '對象:' string
print '取值:' json.loads(string)['code']
輸出結果為:
對象:{u'status': u'error', u'code': 404, u'messages': [u"Could not find resource or operation 'BZK1.MapServer' on the system."]}
取值:404
將對象轉成字符串:
resultJson = {"state": 1} print json.dumps(resultJson)
分別使用了Json包中的loads()方法和dumps()方法
想要了解更多關于Python和人工智能方面內容的小伙伴,請關注扣丁學堂Python培訓官網、微信等平臺,扣丁學堂IT職業(yè)在線學習教育平臺為您提供權威的Python開發(fā)環(huán)境搭建視頻,Python培訓后的前景無限,行業(yè)薪資和未來的發(fā)展會越來越好的,扣丁學堂老師精心推出的Python視頻教程定能讓你快速掌握Python從入門到精通開發(fā)實戰(zhàn)技能。扣丁學堂Python技術交流群:279521237。
【關注微信公眾號獲取更多學習資料】 【掃碼進入Python全棧開發(fā)免費公開課】