-1

我有一个像这样的字符串:

"{
\"__type\":\"DailyRequestItem:#CapitalIQ.DataAPI.Download\",
\"Identifier\":{\"__type\":\"CompanyIdentifier:#CapitalIQ.DataAPI\",\"SearchString\":\"goog\"},
\"FormulaMetric\":{\"MetricName\":\"IQ_LASTSALEPRICE\",\"MetricId\":0},
\"ReturnType\":0,
\"CurrencyConversionInfo\":{\"CurrencyId\":160,\"CurrencyConversionMode\":0},\"Response\":{
\"Id\":0,\"CompanyId\":29096,\"TradingItemId\":11311662,\"RequestedCurrencyId\":0,\"CurrencyConversionModeId\":0,\"Error\":0,\"Values\":[{\"CurrencyConversionDate\":\"\\/Date(-62135578800000-0500)\\/\",\"DataTypeId\":2,\"ReportedCurrencyId\":0,\"Id\":0,\"CurrencyId\":160,\"ScaleId\":0,\"UnitsId\":0,\"ValueId\":0,\"ValueAsString\":\"896.598000\",\"Delimiter\":\",\",\"SubValueList\":null,\"Error\":0,\"ClickThroughTypeId\":0,\"InstanceId\":0,\"PricingDate\":\"\\/Date(1374724800000-0400)\\/\",\"ConversionMode\":0,\"AuditabilityTypeId\":0,\"AsOfDate\":\"\\/Date(1374724800000-0400)\\/\",\"CompanyId\":0,\"DataItemId\":0,\"TradingItemId\":0}]
},
\"RangeInfo\":{\"AsOfDate\":\"\\/Date(1374724800000-0400)\\/\",\"StartDate\":\"\\/Date(-62135596800000)\\/\",\"EndDate\":\"\\/Date(-62135596800000)\\/\",\"Frequency\":1,\"ReturnType\":0,\"TradingDayOffset\":null,\"IsIntraday\":false},\"Period\":null}"

我需要从中删除这部分:

\"Response\":{
\"Id\":0,\"CompanyId\":29096,\"TradingItemId\":11311662,\"RequestedCurrencyId\":0,\"CurrencyConversionModeId\":0,\"Error\":0,\"Values\":[{\"CurrencyConversionDate\":\"\\/Date(-62135578800000-0500)\\/\",\"DataTypeId\":2,\"ReportedCurrencyId\":0,\"Id\":0,\"CurrencyId\":160,\"ScaleId\":0,\"UnitsId\":0,\"ValueId\":0,\"ValueAsString\":\"896.598000\",\"Delimiter\":\",\",\"SubValueList\":null,\"Error\":0,\"ClickThroughTypeId\":0,\"InstanceId\":0,\"PricingDate\":\"\\/Date(1374724800000-0400)\\/\",\"ConversionMode\":0,\"AuditabilityTypeId\":0,\"AsOfDate\":\"\\/Date(1374724800000-0400)\\/\",\"CompanyId\":0,\"DataItemId\":0,\"TradingItemId\":0}]
},    

并将其序列化。我正在使用这个正则表达式,但无济于事:

string pattern = @"\\Response\.\]}";

有人可以帮我形成正则表达式模式吗?请帮忙

4

1 回答 1

1

正如人们建议解析 JSON 响应正则表达式不是一个合适的解决方案,但如果您没有找到任何其他解决方案,您仍然可以使用此模式来解决您的问题:

(\"Response\")[\S\s]*?(?=\"RangeInfo\")

看看这个rubular 演示

笔记:

我希望 JSON 响应将始终采用特定格式,并且RangeInfo元素将是 JSON 响应中的下一个即将到来的节点。

于 2013-08-01T03:32:12.743 回答