我正在尝试从网页获取json数据
http://localhost/widgets/Screenshot_show/?pc_widget_output_method=JSON
进入我的windows窗体应用程序中的c到一个文本框。这是json数据的链接,我试图将时间属性放入文本框中,但没有得到
这就是我们尝试过的
WebClient client = new WebClient(); //gets an object to access a website
string download = client.DownloadString("http://localhost/widgets/Screenshot_show?pc_widget_output_method=JSON"); //download the json file into a string
dynamic dobj = JsonConvert.DeserializeObject<dynamic>(download); //this function of newtonsoft here deserialize json data
string location = (string)dobj["JSON"]["sucess"];
txtwebclient.Text = download;
但我总是在试图将时间属性检索到文本框中时出错
JSON示例:
[
{
"name": "",
"location": "/screenshots/",
"time": 1584498343,
"screenshots_id": "1584498343-0-33",
"creation_time": 1584498343,
"modified_time": "",
"__user_id": 1583761141.0404,
"__update_user_id": null,
"__user_agent_id": "",
"__ip": {
"REMOTE_ADDR": "::1",
"HTTP_CLIENT_IP": "",
"HTTP_X_FORWARDED_FOR": ""
}
}
]
具有对象数组的json。试试这个
var jArray = JArray.Parse(download);
var result = jArray[0]["location"];