将JSON字符串转换为JSON对象

rks48beu  于 2023-05-19  发布在  其他
关注(0)|答案(4)|浏览(260)

我有一个来自Web服务的JSON响应,我需要将其转换为对象,然后转换为数组。我的回答与下面的类似:

{"status":{"error":"NO","code":"200","description":"none","message":"Request ok"},"geolocation":{"lat":"38.89515","lng":"-77.0310"},"stations":[{"country":"United States","regPrice":"0.00","midPrice":"0.00","prePrice":"0.00","streetAddress":"1401, I St NW","ID":"1900","lat":"38.901440","lng":"-77.032127","stationName":"Shell","logo":"http:\/\/www.nyneaxis.com\/logo\/stations\/noLogo.png","state":"District of Columbia","city":"Washington D.C.","regDate":null,"midDate":null,"preDate":null,"distance":"0.7"},{"country":"United States","regPrice":"0.00","midPrice":"0.00","prePrice":"0.00","streetAddress":"2116-2150, M St NW","ID":"13029","lat":"38.905201","lng":"-77.048103","stationName":"Exxon","logo":"http:\/\/www.nyneaxis.com\/logo\/stations\/noLogo.png","state":"District of Columbia","city":"Washington D.C.","regDate":null,"midDate":null,"preDate":null,"distance":"1.9"}]}

我现在正在做的是VB.NET控制台。基本上,我试图创建一个简单的方法来测试我的API调用和输出信息。我试图完成的是必须循环遍历JSON数组并列出车站。我以前从未在VB.NET中这样做过,希望得到一些帮助。我一直阅读反序列化,但不明白它。

mkshixfv

mkshixfv1#

您可以使用Json.NET

Dim ThisToken as JToken = Newtonsoft.Json.JsonConvert.DeserializeObject(Of JToken)(JSonString)
amrnrhlw

amrnrhlw2#

有一个很好的.NET库,叫做Json.NET,它对做这类事情很有用http://json.codeplex.com/
有很多例子,大多数是C#。

sd2nnvve

sd2nnvve4#

如果你使用的是.NET 4.0+,你可以使用JavaScriptSerializer Deserialize方法,检查:Deserialize JSON with JavaScriptSerializer
注意:请记住,您需要有一个.NET类,其中包含要反序列化的JSON对象的所有属性。

相关问题