Click here to Skip to main content
14,773,274 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a URL

i need to fetch data from this URL in grid. Can anyone help me out please.

I am able to see the data in browser when i directly hit the URL in browser but never get it in my code.

What I have tried:

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;

public partial class read_json_with_newtonsoft_json : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
string json = get_web_content("");

dynamic array = JsonConvert.DeserializeObject(json);

Response.Write("Code: " + array.Jaggedarray + "


public string get_web_content(string url)
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string output = reader.ReadToEnd();

return output;
Updated 10-Jun-20 21:12pm
Richard MacCutchan 11-Jun-20 4:35am
Paste that URL into your web browser to check that the JSON being returned is valid.

1 solution

Without actually fetching the data - and I'm not planning on going near an anonymous URL to do that - we can't tell at all what is going on. You need to start by looking at teh data you are deserializing, and at what it produces in your code.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900