【发布时间】:2020-10-12 21:19:00
【问题描述】:
我正在使用 newtonsoft,我需要在 Json 响应中获取两个特定字段:
{
"id": "1233323",
"quoteOptions": [{
"copay": "20%",
"deductables": [{
"deductable": "$250",
"quoteOptions": [{
"pricingAndLimits": {
"reimbursement": "80%",
"copay": "20%",
"deductable": "$250",
"limit": "$4,000",
"annualPremium": "$413.00",
"monthlyPremium": "$34.00"
}
}]
}]
}]
}
我需要在旧版 Intranet (VB.NET) 上执行此操作。我特别需要获取monthlyPremium 字段和id 字段。
我试过了
Dim json As String = Result
Dim ser As JObject = JObject.Parse(json)
Dim data As List(Of JToken) = ser.Children().ToList
Dim output As String = ""
Dim Premium As String = ser("quoteOptions")("deductables")("quoteOptions")("pricingAndLimits")("monthlyPremium")
但我在“免赔额”处收到错误(不存在)。
谢谢:)
【问题讨论】:
-
请在您的示例中包含一个实际的 JSON 字符串,而不是您认为的解释。
-
嗨 Drew,Json 字符串就在帖子的开头
-
使用无效键值访问的 JArray 值:“deductables”。预期为 Int32 数组索引。这就是我得到的错误
-
当你看到[]时,表示你必须输入[number]。所以,ser("quoteOptions")[0]...
-
我用 ("deductables")[0], ("deductables"[0]) 试过了,但还是不行。