get data from dynamic key value in json

前端 未结 2 1714
温柔的废话
温柔的废话 2021-01-01 19:47

The requirement is following:
I have to get the location field from page.

var input= global.input = document.getElementById(\"Location\");
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 20:24

    get value from dynamic json object Using real time currency converter rest api responce

    public async Task ConvertCurrency(float Price, string FromCurrency)
    {
        var testcase = FromCurrency + "_USD";
        WebClient web = new WebClient();
        const string ConverterApiURL = "http://free.currencyconverterapi.com/api/v5/convert?q={0}_{1}&compact=ultra&apiKey={{EnterKey}}";
        string url = String.Format(ConverterApiURL, FromCurrency, "USD");
    
        string response = new WebClient().DownloadString(url);
    
        var data = (JObject)JsonConvert.DeserializeObject(response);
        dynamic result = data.SelectToken(testcase + ".val").ToString();
    
        var basePrice = float.Parse(result);
    
        double exchangeRate = Price * basePrice;
        var responce = Math.Round(exchangeRate, 2);
        return Json(responce, JsonRequestBehavior.AllowGet);
    }
    

提交回复
热议问题