我有这样的 JSON 文本:
...
"simples":{
"AS100ELABQVKANID-91057":{
"meta":{
"sku":"AS100ELABQVKANID-91057",
"price":"3669000.00",
"original_price":"3379000.00",
"special_to_date":"2015-03-19 23:59:59",
"shipment_type":"1",
"special_price":"3299000.00",
"tax_percent":"10.00",
"sourceability":"Sourceable",
"quantity":"15",
"variation":"...",
"package_type_position":"0",
"min_delivery_time":"1",
"max_delivery_time":"3",
"attribute_set_name":"electronics",
"3hours_shipment_available":false,
"estimated_delivery":"",
"estimated_delivery_position":""
},
"attributes":{
"package_type":"Parcel"
}
}
},
"description":
...
以上文本在我的 JSON 文本中重复出现。我正在尝试构建每个结果:
"simples":[],"description"
到目前为止,我已经制作了这个正则表达式:
\"simples\":{(?:.*v(?:|=)|(?:.*)?)},\"description\"
但结果是将所有内容从我的第一个 “simples”
剪切到最后一个 “description”
。
正则表达式新手在这里。
提前致谢
最佳答案
我建议解析 JSON,替换值,然后重新字符串化
var obj = JSON.parse(json);
obj.simples = [];
json = JSON.stringify(obj);
为此使用正则表达式纯粹是疯狂
关于c# - 正则表达式替换 JSON 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22552734/