请考虑下面的JSON提取(数据要大得多,但这是一个较短的片段,我正在尝试使用)
jsonData = """{
"products" : {
"DQ578CGN99KG6ECF" : {
"sku" : "DQ578CGN99KG6ECF",
"productFamily" : "Compute",
"attributes" : {
"location" : "US East (N. Virginia)",
"instanceType" : "hs1.8xlarge",
"tenancy" : "Shared",
"operatingSystem" : "Windows",
"licenseModel" : "License Included",
"preInstalledSw" : "NA"
}
},
"G2N9F3PVUVK8ZTGP" : {
"sku" : "G2N9F3PVUVK8ZTGP",
"productFamily" : "Instance",
"attributes" : {
"location" : "Asia Pacific (Seoul)",
"instanceType" : "i2.xlarge",
"tenancy" : "Host",
"operatingSystem" : "Windows",
"licenseModel" : "License Included",
"preInstalledSw" : "SQL Server Enterprise"
}
},
"FBZZ2TKXWWY5HZRX" : {
"sku" : "FBZZ2TKXWWY5HZRX",
"productFamily" : "Compute",
"attributes" : {
"location" : "Asia Pacific (Seoul)",
"instanceType" : "i2.4xlarge",
"tenancy" : "Dedicated",
"operatingSystem" : "SUSE",
"licenseModel" : "No License required",
"preInstalledSw" : "NA"
}
}
}
}"""
我无法创建一个合适的过滤器来查找所有使用“Windows”作为操作系统和共享租赁的产品。在
我说到这里:
^{pr2}$不过,我还是这样把sku弄丢了。在
结果:
[{
"location" : "US East (N. Virginia)",
"instanceType" : "hs1.8xlarge",
"tenancy" : "Shared",
"operatingSystem" : "Windows",
"licenseModel" : "License Included",
"preInstalledSw" : "NA"
}]
我想要的是:
[
{ "sku": "DQ578CGN99KG6ECF",
"attributes" : {
"location" : "US East (N. Virginia)",
"instanceType" : "hs1.8xlarge",
"tenancy" : "Shared",
"operatingSystem" : "Windows",
"licenseModel" : "License Included",
"preInstalledSw" : "NA"
}
}]
你知道怎么得到结果吗?在
你可以用一个查询完成它:
好吧,我继续寻找答案,我终于成功地得到了我的结果!在
关键是要分两步来做到这一点:)
这是我现在使用的代码:
结果是:
^{pr2}$相关问题 更多 >
编程相关推荐