简体   繁体   中英

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?

导入System.Web.Script.Serialization,然后使用JavaScriptSerializer对象。

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM