2017-05-04 4 views
-3

J'utilise une requête GET à Shopify et Shopify renvoie un JSON ..données d'objet et d'affichage dictionnaire boucle

Je désérialisation JSON à l'objet ci-dessous (dictionnaire) ...

Comment puis-je parcourez l'objet ci-dessous et accédez uniquement à la paire de valeurs de clé "title" .

<code> 
    @using System.Web.Script; 
    @using System.Web.Script.Serialization; 
    @{ 
     var url = string.Format("https://{0}.myshopify.com/admin/orders.json? 
     fields=billing_address", AppState["ShopName"]); 
     var request = (HttpWebRequest)WebRequest.Create(url); 
     request.Method = "GET"; 
     request.ContentType = "application/json"; 
     request.Credentials=new 
     NetworkCredential((string)AppState["PrivateAppKey"], 
     (string)AppState["PrivateAppSecret"]); 
     request.PreAuthenticate = true; 

     WebResponse response = request.GetResponse(); 

     StreamReader reader = new StreamReader(response.GetResponseStream()); 
     string urlText = reader.ReadToEnd(); // response from your url. 

     var jsonSerializer = new JavaScriptSerializer(); 
     dynamic brokenJson = jsonSerializer.Deserialize<dynamic>(urlText); 

    } 
</code> 
 

    Dictionary 
    string "blogs" = object[] 
    [0] = Dictionary 
    string "id" = int 94686854 
    string "handle" = string "3d-printing" 
    string "title" = string "3D Printing" 
    string "updated_at" = string "2017-04-04T23:56:33+05:30" 
    string "commentable" = string "moderate" 
    string "feedburner" = string "" 
    string "feedburner_location" = string "" 
    string "created_at" = string "2017-04-04T23:56:33+05:30" 
    string "template_suffix" = (null) 
    string "tags" = string "" 
    [1] = Dictionary 
    string "id" = int 47272710 
    string "handle" = string "news" 
    string "title" = string "News about ATRANGI" 
    string "updated_at" = string "2017-04-07T13:20:45+05:30" 
    string "commentable" = string "yes" 
    string "feedburner" = string "Atrangi-LatestNews" 
    string "feedburner_location" = string "http://feeds.feedburner.com/" 
    string "created_at" = string "2016-01-06T20:56:04+05:30" 
    string "template_suffix" = (null) 
    string "tags" = string "" 

+4

S'il vous plaît montrer JSON et désérialisation. Cela va rendre beaucoup plus facile –

+1

J'ai voté pour fermer cette question, car il n'est pas clair à lire. – Hackerman

+0

@Gautam Sharma, est-ce que tu résous le problème? – gabba

Répondre

0

Vous did't spectacle assez pour répondre, mais probablement que vous devez faire ceci:

foreach(var blog in yourObject["blogs"]) 
{ 
    var title = blog["title"]; 
} 
+0

@giladgreen ci-dessous est le code qui demande l'API –

+0

@GautamSharma est-ce que vous résolvez votre problème – gabba