shahjagat
asked on
Need to Interpret Json in Vb.net ( .net 3.5 framework)
Hello All,
We are into process of migrating from Bing Map v7 to Bing Map v8.
From last many years we are using Visual Studio 2008 and Bing Map Version 7.
We recently have received email from Microsoft that June-30-2017 is declared as end of life for Bing Map v7.
Our integrated/production environment is set up like below
1. We are dependent on SOAP based services of Bing Map V7 ( For geocoding, etc... )
2. We are also dependent on Javascript based services of Bing Map V7 Interaction ( for loading map etc...)
3. we are using .net 3.5 framework
Now Microsoft in V8 is stopping SOAP service completely and They are provide only REST based service
My Problem Definition
Microsoft had provided great materials for javascript migration but they have not provided good material for migration of Soap to Rest Services.
While working on rest response of Bing Map V8, I found that their response is in JSON format. then I came across below list of libraries
1. Newton.json library
2. http://www.json.org/
My Question to you all is that
I need your help in finding open source VB.net library ( if any ) so that I should have good control on the entire code for future issues.
Thanks in advance.
We are into process of migrating from Bing Map v7 to Bing Map v8.
From last many years we are using Visual Studio 2008 and Bing Map Version 7.
We recently have received email from Microsoft that June-30-2017 is declared as end of life for Bing Map v7.
Our integrated/production environment is set up like below
1. We are dependent on SOAP based services of Bing Map V7 ( For geocoding, etc... )
2. We are also dependent on Javascript based services of Bing Map V7 Interaction ( for loading map etc...)
3. we are using .net 3.5 framework
Now Microsoft in V8 is stopping SOAP service completely and They are provide only REST based service
My Problem Definition
Microsoft had provided great materials for javascript migration but they have not provided good material for migration of Soap to Rest Services.
While working on rest response of Bing Map V8, I found that their response is in JSON format. then I came across below list of libraries
1. Newton.json library
2. http://www.json.org/
My Question to you all is that
I need your help in finding open source VB.net library ( if any ) so that I should have good control on the entire code for future issues.
Thanks in advance.
Not to mention that parsing JSON is not so daunting once you get used to the format. JSON objects represent javascript objects which are *usually* serialized as strings.
The curly braces ({}) identify regular objects. A regular json objects contains key:value pairs delimited by commas; e.g. -
Carrying on, the brackets in JSON ([]) represent array objects. Array objects contain elements seperated by commas. The array elements are nothing more than objects; e.g. -
Again, keep in mind that arrays, and their contents, can be well-defined as well; e.g. -
-saige-
The curly braces ({}) identify regular objects. A regular json objects contains key:value pairs delimited by commas; e.g. -
{ "one": "1", "two": 2 }
The object just defined would be represented like this in VB.NET -
Class MyObject
Public Property One() As String
Public Property Two() As Integer
End Class
JSON Objects can also be well-defined; e.g. -
"oneTwo": { "one": "1", "two": 2 }
To parse this definition of the object, we would change the preceeding VB.NET class as such -
Class OneTwo
Public Property One() As String
Public Property Two() As Integer
End Class
You could also use attributes to map the object; e.g. -
<JsonObject("OneTwo")> _
Class MyObject
Public Property One() As String
Public Property Two() As Intger
End Class
I won't go into great detail about attributes just want to include a teaser. You can read more about attributes here: http://www.newtonsoft.com/json/help/html/serializationattributes.htmCarrying on, the brackets in JSON ([]) represent array objects. Array objects contain elements seperated by commas. The array elements are nothing more than objects; e.g. -
[{ "one": "1", "two": 2 }, { "one": "3", "two", 4 }, { "one": "5", "two": 6 }]
The most common representation of a JSON array in VB.NET is either an array or a list.Again, keep in mind that arrays, and their contents, can be well-defined as well; e.g. -
{"oneTwos": [{ "oneTwo": { "one": "1", "two": 2 }}, { "oneTwo": { "one": "3", "two": 4 }}, { "oneTwo": { "one": "5", "two": 6 }}]}
-saige-
ASKER
First of all Thanks a lot Saige and Ste5an for your response.
can you please confirm my below doubts
1. is Nuget is available only for .net 4.5 framework, because we are using .net 3.5
2. how to find middle path with which I should not have to migrate to .net 4.5 and I am able use nuget library
Thanks in advance
can you please confirm my below doubts
1. is Nuget is available only for .net 4.5 framework, because we are using .net 3.5
2. how to find middle path with which I should not have to migrate to .net 4.5 and I am able use nuget library
Thanks in advance
ASKER
While doing research I come across " System.Web.Script.Serializ ation "
I attempted to use it i works well interpret well with simple json string, but it is not able to interpret below string.
it gives me this error "Value cannot be null. Parameter name: type"
Below is string from bing map for one of our input and FYI I am VS2008 ( vb.net )
My Code
My Class
I attempted to use it i works well interpret well with simple json string, but it is not able to interpret below string.
it gives me this error "Value cannot be null. Parameter name: type"
Below is string from bing map for one of our input and FYI I am VS2008 ( vb.net )
My Code
Dim vBM_String = "{""authenticationResultCode"":""ValidCredentials"",""brandLogoUri"":""http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png"",""copyright"":""Copyright © 2017 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation."",""resourceSets"":[{""estimatedTotal"":1,""resources"":[{""__type"":""Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1"",""bbox"":[28.3878372824293,-97.7645242687346,28.3955627175707,-97.7528157312654],""name"":""602 S Alta Vista Blvd, Beeville, TX 78102"",""point"":{""type"":""Point"",""coordinates"":[28.3917,-97.75867]},""address"":{""addressLine"":""602 S Alta Vista Blvd"",""adminDistrict"":""TX"",""adminDistrict2"":""Bee"",""countryRegion"":""United States"",""formattedAddress"":""602 S Alta Vista Blvd, Beeville, TX 78102"",""locality"":""Beeville"",""postalCode"":""78102""},""confidence"":""High"",""entityType"":""Address"",""geocodePoints"":[{""type"":""Point"",""coordinates"":[28.3917,-97.75867],""calculationMethod"":""Rooftop"",""usageTypes"":[""Display""]},{""type"":""Point"",""coordinates"":[28.3918349436365,-97.7583584300792],""calculationMethod"":""Rooftop"",""usageTypes"":[""Route""]}],""matchCodes"":[""Good""]}]}],""statusCode"":200,""statusDescription"":""OK"",""traceId"":""b302f769b0f9451fa27dde0db0c07aad|HK20280423|7.7.0.0|""}"
Dim vBM_JSon = New JavaScriptSerializer()
Dim SSBM_model As SSGeocode = vBM_JSon.Deserialize(Of SSGeocode)(vBM_String)
HttpContext.Current.Response.Write("<br>")
HttpContext.Current.Response.Write(SSBM_model.statusCode)
HttpContext.Current.Response.Write("<br>")
HttpContext.Current.Response.Write(SSBM_model.authenticationResultCode)
My Class
Public Class SSGeocode
Private _authenticationResultCode As String
Private _statusCode As String
Private _resourceSets As Object
Public Property authenticationResultCode() As String
Get
Return _authenticationResultCode
End Get
Set(ByVal value As String)
_authenticationResultCode = value
End Set
End Property
Public Property statusCode() As String
Get
Return _statusCode
End Get
Set(ByVal value As String)
_statusCode = value
End Set
End Property
Public Property resourceSets() As Object
Get
Return _resourceSets
End Get
Set(ByVal value As Object)
_resourceSets = value
End Set
End Property
End Class
The NuGet Package Manager (NPM) has been available in Visual Studio since 2010. It is not .NET specific. It *is*, however, powershell 2.0 depended. There are projects available on GitHub that even allow for NuGet to be used on VS 2005 and VS 2008; e.g. - https://github.com/paypal/sdk-core-dotnet/wiki/Using-Nuget-in-Visual-Studio-2005-&-2008
Even if you cannot use NuGet, the Newtonsoft Json.NET Library supports .NET 2, .NET 3.5, .NET 4, .NET 4.5, Silverlight, Windows Phone and Windows 8 Store and it can be downloaded and installed manually.
http://www.newtonsoft.com/json/help/html/Introduction.htm
-saige-
Even if you cannot use NuGet, the Newtonsoft Json.NET Library supports .NET 2, .NET 3.5, .NET 4, .NET 4.5, Silverlight, Windows Phone and Windows 8 Store and it can be downloaded and installed manually.
http://www.newtonsoft.com/json/help/html/Introduction.htm
-saige-
just type nuget in the Quick Lunch box in Visual Studio (upper-right corner) after loading your project. NuGet will retrieve and add the correct .NET version of the packages according to your project settings.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello -saige-,
Big thanks about your effort.
I copied your code in my project, but I am not get value of
geoCode.ResourceSets(0).Re sources(0) .Type
As per string given to you value should be " Location:http://schemas.microsoft.com/search/local/ws/rest/v1 ", but I am getting it as blank, I am not sure but I suspect it because inside json it prefix with 2 under_score special character like
Please answer
Thanks in advance
Big thanks about your effort.
I copied your code in my project, but I am not get value of
geoCode.ResourceSets(0).Re
As per string given to you value should be " Location:http://schemas.microsoft.com/search/local/ws/rest/v1 ", but I am getting it as blank, I am not sure but I suspect it because inside json it prefix with 2 under_score special character like
"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1"
Please answer
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot -saige-
I really appreciate your effort.
I really appreciate your effort.
ASKER
Thanks to all
OOP and SOLID are your friends. Create your service façade of the bing services as an interface. Implement your code against it. This will give you the necessary safety cause you've decoupled your code from the external service.