繁体   English   中英

访问反序列化JObject中的属性(Json.Net)

[英]Accessing Attributes in Deserialized JObject (Json.Net)

我使用来自Json.Net的JObject(o)反序列化了下面显示的Json。 我已经成功地解决了一些属性,例如o [“ items”] [0] [“ formattedURL”]可以正常工作。 但是,我遇到了类似o [“ queries”] [“ nextPage”] [“ startIndex”]之类的问题,我想返回'11',但会引发错误。 我已经广泛地寻找有关此方面的文档,但是没有运气。

{
 "kind": "customsearch#search",
 "url": {
  "type": "application/json",
  "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
 },
 "queries": {
  "nextPage": [
   {
    "title": "Google Custom Search - Action Motivation, Inc.",
    "totalResults": "1980000",
    "searchTerms": "Action Motivation, Inc.",
    "count": 10,
    "startIndex": 11,
    "inputEncoding": "utf8",
    "outputEncoding": "utf8",
    "safe": "off",
    "cx": {cxkey},
   }
  ],
.
.
.
  {
   "kind": "customsearch#result",
   "title": "Action Motivation, Inc.",
   "htmlTitle": "\u003cb\u003eAction Motivation, Inc\u003c/b\u003e.",
   "link": "http://www.amotive.com/",
   "displayLink": "www.amotive.com",
   "snippet": "Provides corporate and special event planning and conference management \nservices. South San Francisco, CA.",
   "htmlSnippet": "Provides corporate and special event planning and conference management \u003cbr\u003e\nservices. South San Francisco, CA.",
   "cacheId": "CVRUP-rsFioJ",
   "formattedUrl": "www.amotive.com/",
   "htmlFormattedUrl": "www.amotive.com/",
   "pagemap": {
    "metatags": [
     {
      "rating": "general",
      "resource-type": "document",
      "msvalidate.01": "4FA3F444F3F4ABC8052E636B39D4D01B"
     }
    ]
   }
  },

查看JSON, nextPage是一个数组,但是尝试像对象一样调用,因此抛出错误。

像下面这样

o["queries"]["nextPage"][0]["startIndex"] 
                 |       |____index of the array
                 |____________ Array type

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM