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.

2 Answers 2

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");
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.