簡體   English   中英

從JObject提取值

[英]Extract Values from JObject

我正在嘗試從Json提取一些值,但是[]之間的數據存在問題

{ 
  attrib1: ""es-BO"",
  attrib2: 2,
  Segment: [
  {
    inAttrib1: ""value1"",
    inAttrib2: ""value2"",
    inAttrib3: ""value3""
  }]
}

對於我正在使用的第一個值:

string attrib1 = request.GetValue("attrib1").Value<string>();
.
.
.

但是當我嘗試做的時候:

string inAttrib1 = request.GetValue("inAttrib1").Value<string>();

不起作用...我該怎么辦?或存在另一種方法來做同樣的事情

[]之間(包括)之間的數據稱為數組 在繼續之前,查看JSON主頁可能會有所幫助,特別是查看可用的不同數據類型。

您需要向下導航到Segment數組,然后獲取第一個元素,然后獲取該元素的inAttrib1屬性:

string attrib1Value = request["Segment"][0]["inAttrib1"].Value<string>();

或者:

string attrib1Value = request.SelectToken(@"Segment[0].inAttrib1").Value<string>()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM