Bagaimana cara menggunakan python untuk mengekstrak medan dari fail json?
習慣沉默
習慣沉默 2017-05-18 10:53:08
0
2
725

Kini terdapat data json, seperti berikut:

{
"kegemaran":{

  "bkmrk":{
     "id1490843709594066":{
        "guid":"904eff52277f403b89f6410fe2758646.11",
        "lcate":"1"
     },
     "id1490843712805183":{
        "guid":"58457f60eca64025bc43a978f9c98345.16",
        "lcate":"2"
     },
     "id149084371467327":{
        "guid":"a0f907f9dc8b40f689b083f3eba7228b.16",
        "lcate":"3"
     },
     "id1490843716295393":{
        "guid":"eb75d929455e468bb712e7bc2025d11a.16",
        "lcate":"4"
     }
  }

)
"guid":"a0f907f9dc8b40f689b083f3eba7228b.16 "
"guid":"eb75d929455e468bb712e7bc2025d11a.16"

習慣沉默
習慣沉默

membalas semua(2)
刘奇
import json

with open('json.txt', 'r') as fp:
    data = json.load(fp)
    print(data)

dataItulah yang anda mahukan.

伊谢尔伦
import json
a = '''{ "favourite":{

  "bkmrk":{
     "id1490843709594066":{
        "guid":"904eff52277f403b89f6410fe2758646.11",
        "lcate":"1"
     },
     "id1490843712805183":{
        "guid":"58457f60eca64025bc43a978f9c98345.16",
        "lcate":"2"
     },
     "id149084371467327":{
        "guid":"a0f907f9dc8b40f689b083f3eba7228b.16",
        "lcate":"3"
     },
     "id1490843716295393":{
        "guid":"eb75d929455e468bb712e7bc2025d11a.16",
        "lcate":"4"
     }
  }
}
}'''
result = [{'guidi': i[1]['guid']} for i in json.loads(a)['favourite']['bkmrk'].iteritems()]
print result 

# 输出结果:
[{'guidi': u'904eff52277f403b89f6410fe2758646.11'}, {'guidi': u'a0f907f9dc8b40f689b083f3eba7228b.16'}, {'guidi': u'eb75d929455e468bb712e7bc2025d11a.16'}, {'guidi': u'58457f60eca64025bc43a978f9c98345.16'}]
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!