Progger
Progger

Reputation: 2254

Trying to parse JSON from a url using C#

I have an exe file I wrote in .NET which I want to read a .json file from a URI, and return a value in string format. I am pretty new to .NET and c# but can easily do this in PowerShell (using Invoke-RestMethod). I don't want to use an external library such as json.net (would like to distribute this as a single .exe). The only thing I found so far was System.Runtime.Serialization.Json - which looks like it will work but also seems extremely complex and difficult to use. Is this the library I should be using to perform this simple task? Is there an easier way to do this?

Upvotes: 2

Views: 265

Answers (3)

lcryder
lcryder

Reputation: 496

import System.Web.Script.Serialization, then use JavaScriptSerializer object.

Upvotes: 3

miskiw
miskiw

Reputation: 94

If you don't want to parse your own JSON I think the System.Runtime.Serialization.Json namespace is your best bet without using an external library..

JSON.NET is the best if you can use an external library though

Upvotes: 1

Reinderien
Reinderien

Reputation: 15231

System.Runtime.Serialization.Json really isn't all that bad. Yes, it is the library you should use if you don't want to go third-party.

The exception to this is if your JSON is trivial. If it's trivial, just do the string parsing yourself.

Upvotes: 1

Related Questions