c# - 正则表达式替换 JSON 结构

标签 c# regex json json.net

我有这样的 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/

相关文章:

c# - rabbitmq 消费者成为生产者

c# - 从 TextBlock 获取带有换行符的文本?

c# - 您如何设置 .NET 开发树?

python - python中的文件路径

javascript - 为什么这个对 api 的调用不适用于 3 个字母的单词?

c# - 使用 ImapX 和 C# 未正确保存下载的电子邮件附件

regex - 使用模式匹配的奇怪 perl foreach 行为

用于手机号码验证的正则表达式

Python 正则表达式 : I want to remove newlines after every '%}' tag close except for content in between {% verbatim%} . .. {% endverbatim %} 标签

json - Dart lang 不止一个 window.message.add