You must Sign In to post a response.
  • Category: ASP.NET

    Get data from Json URL in

    I have json URL and i want to implement in the Asp.NET,EUR,AED,CAD

    Result in web page is:
    "disclaimer": "Usage subject to terms:",
    "license": "",
    "timestamp": 1517025604,
    "base": "USD",
    "rates": {
    "AED": 3.673018,
    "CAD": 1.231755,
    "EUR": 0.804525,
    "GBP": 0.706185

    I want to display the above result in page. I tried the code as below but nothing to shown in the page.
    My code as below:
    <form id="form1" runat="server">
    <script type = "text/javascript" language = "javascript">
    $.get('', {app_id: 'Y0277d31956db4d57af7207ca1ab782a5', symbols: 'QAR,RUB,SEK'}, function(data) {
    var text = 'Result: ${ data.rates.SEK}';
  • #769482
    using System.Net;
    using Newtonsoft.Json;

    // ...

    private static T _download_serialized_json_data<T>(string url) where T : new() {
    using (var w = new WebClient()) {
    var json_data = string.Empty;
    // attempt to download JSON data as a string
    try {
    json_data = w.DownloadString(url);
    catch (Exception) {}
    // if string with JSON data is not empty, deserialize it to class and return its instance
    return !string.IsNullOrEmpty(json_data) ? JsonConvert.DeserializeObject<T>(json_data) : new T();

  • #769492
    You must convert the response into Json and then append the data in your view. Below is some piece of code

    public async Task<ActionResult> Printer()
    string url = "https://localhost/api/test/";
    HttpResponseMessage responseMessage = await client.GetAsync(url);
    if (responseMessage.IsSuccessStatusCode)
    var responseData = responseMessage.Content.ReadAsStringAsync().Result;
    var campusName = JsonConvert.DeserializeObject<List<OrgCampus>>(responseData);
    cs.getCampus = campusName;
    return View(cs);
    return View("Error");

    Gopi A.
    +91 9894315571

  • Sign In to post your comments