我有一个json文件
{
"SystemId": "VARinicom2",
"SystemName": "EO System",
"SensorType": "Visual",
"Latitude": 1.3391904,
"Longitude": 103.7414429
}
此文件位于此URL
https://api.myjson.com/bins/1crza2
如果我想使用C#每秒更新一次纬度和经度,怎么办呢?
我尝试做一些简单的事情。
public class RunJsonDemo
{
static string url = "https://api.myjson.com/1crza2";
string json = File.ReadAllText(url);
dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
jsonObj["Latitude"] = "new latitude";
}
它不起作用,我该怎么办?
这是我到目前为止所做的
public static void HTTP_PuttoURL(string requestUri, string data)
{
try
{
WebRequest req = WebRequest.Create(requestUri);
req.Method = "PUT";
req.Timeout = 10000;
req.ContentType = "application/json";
byte[] sentData = Encoding.UTF8.GetBytes(data);
req.ContentLength = sentData.Length;
using (Stream sendStream = req.GetRequestStream())
{
sendStream.Write(sentData, 0, sentData.Length);
sendStream.Close();
}
}
catch (Exception ex)
{
}
}
网址中的文件未更新