2010-03-17 4 views
0

je le JSON suivant:JSON problèmes d'analyse syntaxique

"{\" doc \ ": {\" info \ ": {\" allowDistribution \ ": \" true \ "\" allowSearch \ ": \" true \ ", \" calaisRequestID \ ": \" 67a02f61-7e45-cfc4-1276-e123c5f7422f \ ", \" externalID \ ", \" \ ", \" id \ ": \" http://id.opencalais.com/dBo1YRiQeqS-kfO-m9UeWA \ " , \ "docId \": \ "http://d.opencalais.com/dochash-1/8edabb36-eece-3f67-b187-ab64cd885ecb \", \ "document \": \ "Quel type de musique écoutez-vous? Combien paieriez-vous pour un CD? Achètes-tu toujours des CD? Aimez-vous Shakira? Quel genre de musique écoutez-vous? \ ", \" DocTitle \ ": \" \ ", \" docDate \ ": \" 2010-03-17 17: 40: 41.323 \ ", \" externalMetadata \ ": \ "\", \ "envoyeur \": \ "\"}, \ "méta \": {\ "contentType \": \ "text/raw \", \ "emVer \": \ "7.1.1103.5 \ ", \" langIdVer \ ": \" DefaultLangId \ ", \" processingVer \ ": \" CalaisJob01 \ ", \" submitionDate \ ": \" 2010-03-17 17: 40: 41.183 \ ", \" submitterCode \ ": \" b54c734e-b865-185b-c83a-66e1c66272de \ ", \" signature \ ": \" digestalg-1 | FXnvwLovOsqVoSPX0JfGvj3tp7s = | cyV2tZWY9OXG1RBO0SuND4kd3Pkvqv0cS2YpsEBQhXDfSV4KoE61sQ == \ ", \" langue \ ": \" Français \ ", \ "messages \": []}}, \ "http://d.opencalais.com/dochash-1/8edabb36-eece-3f67-b187-ab64cd885ecb/cat/1 \": {\ "_ typeGroup \": \ "sujets \", \ "catégorie \": \ "http://d.opencalais.com/cat/Calais/EntertainmentCulture \", \ "classifierName \": \ " Calais \ ", \" categoryName \ ": \" Entertainment_Culture \ ", \" score \ ": 1}, \" http://d.opencalais.com/dochash-1/8edabb36-eece-3f67-b187-ab64cd885ecb/cat/2 \ ": {\" _ typeGroup \ ": \" sujets \ ", \" catégorie \ ": \ "http://d.opencalais.com/cat/Calais/HumanInterest \", \ "classifierName \": \ "Calais \", \ "nomCatégorie \": \ "Intérêt \" \ "\", \ "score \": 1}, \ "http://d.opencalais.com/dochash-1/8edabb36-eece-3f67-b187-ab64cd885ecb/cat/3 \": {\ "_ typeGroup \ ": \" rubriques \ ", \" catégorie \ ": \" http://d.opencalais.com/cat/Calais/TechnologyInternet \ "\ "classifierName \": \ "Calais \", \ "categoryName \": \ "Technology_Internet \", \ "note \": 0,932}}"

Pouvez-vous s'il vous plaît me dire pourquoi ça ne va pas analyser cela?

Ceci est mon code:

JObject o = JObject.Parse(json); 
String category = (string)o["doc"]["_typeGroup"]["categoryName"]; 

Il me dit:

Référence d'objet non définie à une instance d'un objet.

Merci :)

Répondre

2

_typeGroup n'est pas sous doc, mais est en fait sous http://d.opencalais.com/dochash-1/8edabb36-eece-3f67-b187-ab64cd885ecb/cat/1, comme categoryName.

+0

wow merci beaucoup! de toute façon comment je peux obtenir le nombre de catégories si? –

+0

On dirait que vous pouvez probablement l'obtenir en comptant le nombre de clés qui commencent par la valeur dans 'o [" doc "] [" info "] [" docId "]'. –

Questions connexes