-3

I am using a GET request to shopify and shopify returns a json..

I am deserializing the json to the below object(Dictionary)...

How can I loop through the below object and access only the "title" key value pair.

<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 ""

Gautam Sharma
  • 65
  • 1
  • 7

1 Answers1

0

You did't show enough to answer, but probably you need to do this:

foreach(var blog in yourObject["blogs"])
{
   var title = blog["title"];
}
gabba
  • 2,815
  • 2
  • 27
  • 48