1

I want to simply return a JsonResult in C# from an online API service (iTunes). What I am wanting to do is just go out get the data in JSON format and return that exact data in the same JSON format so I can play with it in javascript.

Here is what I have:

public JsonResult Index()
        {
            using (var client = new WebClient())
            {
                var json = client.DownloadString("https://itunes.apple.com/lookup?id=909253");

                return json;
            }

        }

I am noticing I can't return the json because it is now a string. I don't want to bind this to a model!!! I just want to return a JSON object exactly how I got it.

allencoded
  • 7,015
  • 17
  • 72
  • 126

2 Answers2

2

Change your method signature to return a string instead of a JsonResult object…

public string Index()
{
    using (var client = new WebClient())
    {
        return client.DownloadString("https://itunes.apple.com/lookup?id=909253");
    }
}
Matt Welch
  • 670
  • 4
  • 11
0

Already given answer is ok to get json in javascript.. javasript will treat this string same as if your return json object..

However if you have to get a json object from string in c# anyway then check the accepted answer here

Parse JSON String to JSON Object in C#.NET

Community
  • 1
  • 1
Sami
  • 8,168
  • 9
  • 66
  • 99