2016-06-10 12 views
0

Dies ist ein JSON-String ich habe und ich versuche, es zu analysieren, den „Preis zu bekommen, aber es kommt immer wieder null, klebte unten ist, was ich versucht habe, kann mir bitte jemand helfen?JSON SelectToken Rückkehr null

JSON String

{ 
    "data": { 
     "id": "529665606157020735", 
     "metadata": { 
      "product": { 
       "offer": { 
        "price": "$72", 
        "in_stock": true 
       } 
      }, 
      "link": { 
       "locale": "en", 
       "title": "Missguided Lace Trim Crepe Bardot Romper | Nordstrom", 
       "site_name": "Nordstrom", 
       "description": "Free shipping and returns on Missguided Lace Trim Crepe Bardot Romper at Nordstrom.com. Playful lace insets trim the off-the-shoulder bodice of this breezy flutter-sleeve romper, while sweet scallops detail the hem to complete the look.", 
       "favicon": "https://s-media-cache-ak0.pinimg.com/favicons/4f607a214d617b57b7e45330f8f9135392b7b569f688523cc64bff6e.png?944d8af95205d57ea43fd0128d28a846" 
      } 
     } 
    } 
    } 

Parsing Script:

jsonstring = await response.Content.ReadAsStringAsync(); 
JObject jresults = JObject.Parse(jsonstring); 
string price = (string)jresults.SelectToken("metadata.product.offer.price"); 

Antwort

0

Versuchen Sie folgendes:

JSON:

var obj = { 
    "data": { 
     "id": "529665606157020735", 
     "metadata": { 
      "product": { 
       "offer": { 
        "price": "$72", 
        "in_stock": true 
       } 
      }, 
      "link": { 
       "locale": "en", 
       "title": "Missguided Lace Trim Crepe Bardot Romper | Nordstrom", 
       "site_name": "Nordstrom", 
       "description": "Free shipping and returns on Missguided Lace Trim Crepe Bardot Romper at Nordstrom.com. Playful lace insets trim the off-the-shoulder bodice of this breezy flutter-sleeve romper, while sweet scallops detail the hem to complete the look.", 
       "favicon": "https://s-media-cache-ak0.pinimg.com/favicons/4f607a214d617b57b7e45330f8f9135392b7b569f688523cc64bff6e.png?944d8af95205d57ea43fd0128d28a846" 
      } 
     } 
    } 
}; 

Skript:

var result = obj.data.metadata.product.offer.price; 
console.log(result); 

Ausgang:

enter image description here

Fiddle demo:https://jsfiddle.net/o6upskoy/

+0

Dank @RohitJindal! Ändern des Pfades zu Zeichenfolge price = (string) jresults.SelectToken ("data.metadata.product.offer.price"); behebt das Problem. – Melody

+0

@Melody upvote und markieren Sie dies als eine richtige Antwort, so wird es auch für andere nützlich sein. –