【发布时间】:2017-05-04 20:25:50
【问题描述】:
我正在使用 GET 请求进行 shopify 和 shopify 返回一个 json..
我正在将 json 反序列化为以下对象(字典)...
我怎样才能遍历下面的对象并只访问 “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>
字典
字符串“博客”=对象[]
[0] = 字典
字符串“id”=int 94686854
字符串“手柄” = 字符串“3d 打印”
字符串“标题” = 字符串“3D 打印”
字符串“updated_at”=字符串“2017-04-04T23:56:33+05:30”
字符串“可评论”=字符串“中等”
字符串“feedburner”=字符串“”
字符串“feedburner_location”=字符串“”
字符串“created_at”=字符串“2017-04-04T23:56:33+05:30”
字符串“模板后缀”=(空)
字符串“标签”=字符串“”
[1] = 字典
字符串“id”=int 47272710
字符串“句柄”=字符串“新闻”
string "title" = string "关于 ATRANGI 的新闻"
字符串“updated_at”=字符串“2017-04-07T13:20:45+05:30”
字符串“可评论”=字符串“是”
字符串“feedburner”=字符串“Atrangi-LatestNews”
字符串“feedburner_location”=字符串“http://feeds.feedburner.com/”
字符串“created_at”=字符串“2016-01-06T20:56:04+05:30”
字符串“模板后缀”=(空)
字符串“标签”=字符串“”
【问题讨论】:
-
请显示json和反序列化。会让事情变得更容易
-
我投票结束这个问题,因为它不清楚阅读。
-
@Gautam Sharma,你的问题解决了吗?
标签: c# asp.net c#-4.0 shopify asp.net-webpages