从JObject提取值 [英] Extract Values from JObject

查看:1241
本文介绍了从JObject提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Json提取一些值,但是[]之间的数据存在问题

I'm trying to extract some values from a Json but I have problems with the data between [ ]

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

我正在使用的第一个值:

for the first values I'm using:

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

但是当我尝试做时:

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

不起作用...我该怎么办?,或者存在另一种方法来做同样的事情

doesn't work...what can I do?, or exists another way to do the same

推荐答案

[]之间(包括该位置)之间的数据称为 array .在继续之前,最好先查看 JSON的主页,特别是在可用的不同数据类型上.

The data between (and including) [] is called an array. Before moving on it might be helpful to look at JSON's home page, specifically at the different data types available.

您需要向下导航至Segment数组,然后获取第一个元素,然后获取该元素的inAttrib1属性:

You need to navigate down to the Segment array, then get the first element, then that element's inAttrib1 property:

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

或者:

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

这篇关于从JObject提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆