我正在使用GET请求购物并购物返回json ..
我将json反序列化为下面的对象(Dictionary)...
如何遍历以下对象并仅访问 "标题"键值对。
<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 ""
答案 0 :(得分:0)
你没有表现出足够的答案,但可能你需要这样做:
foreach(var blog in yourObject["blogs"])
{
var title = blog["title"];
}