0

I have a json file

{
    "SystemId": "VARinicom2",
    "SystemName": "EO System",
    "SensorType": "Visual",
    "Latitude": 1.3391904,
    "Longitude": 103.7414429
}

This file is at this URL

https://api.myjson.com/bins/1crza2

If I want to update the Latitude and Longitude every seconds using C#, how can it be done?

I try to do something simple.

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

It is not working, what should I do?

This is what I did so far

  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)
           {

           }
       }

THE FILE IN THE URL IS NOT UPDATED

user2399158
  • 501
  • 1
  • 8
  • 21
  • `It is not working` what does it mean? You want to update the file which is located at the URL or you want to download the json and change it and then save it locally? – Chetan Ranpariya May 15 '18 at 01:55
  • Update the file in the URL – user2399158 May 15 '18 at 02:02
  • You can do that this way... You are downloading the json and changing it, it won't update to the server. You need to see if there is another API which you can use to post the modified json value. – Chetan Ranpariya May 15 '18 at 02:05
  • Show me the code if possible – user2399158 May 15 '18 at 02:09
  • Share the URL of the API to update JSON if you have it... without that code is useless.. – Chetan Ranpariya May 15 '18 at 02:27
  • 1
    Follow this http://myjson.com/api to understand the APIs of myjson.com and https://stackoverflow.com/questions/9145667/how-to-post-json-to-the-server to understand how to post data to API let me know if you face any issue in that – Chetan Ranpariya May 15 '18 at 02:29
  • Your question is not clear, with limited understanding, you need to have some handle to update data. Either the data file from which the API end point reads or end point api to update the data. There is no other way to do it. – Daman Pal Singh Khanna May 15 '18 at 02:44
  • try this for PUT using(var client = new System.Net.WebClient()) { client.UploadData(address,"PUT",data); } – AmirNorouzpour May 15 '18 at 04:09

0 Answers0