0
我想簡單解析一個json與TCL。在使用json2dict解析後,如何在json中處理數組並不明顯。tcl json解析:如何處理數組
這裏是我的代碼:
package require json
set jsonStr {
{ "photos": { "page": 1, "pages": "726", "perpage": 3, "total": "7257",
"photo": [
{ "id": "6974156079", "owner": "[email protected]", "secret": "005d743f82", "server": "7197", "farm": 8, "title": "Kenya Watamu \"Deep Sea Fishing\" \"Indian Ocean\" \"Blue Marlin\"", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "6822988100", "owner": "[email protected]", "secret": "56630c18e8", "server": "7183", "farm": 8, "title": "Gedi Ruins, Local Guide", "ispublic": 1, "isfriend": 0, "isfamily": 0 },
{ "id": "6822909640", "owner": "[email protected]", "secret": "f4e392ea36", "server": "7063", "farm": 8, "title": "Local Fisherman, Mida Creek", "ispublic": 1, "isfriend": 0, "isfamily": 0 }
] }, "stat": "ok" }
}
set d1 [json::json2dict $jsonStr]
foreach key [dict keys $d1] val [dict values $d1] {
puts "The value associated with $key is $val"
}
puts "list of photos:"
set photos [ dict get $d1 photos photo ]
puts $photos
而且我希望能夠遍歷的,我在代碼末尾顯示照片列表。
感謝