Parsing A JSON Array?
May 6, 2011I'm trying to parse this array using JSON.NET
[Code]...
I'm trying to parse this array using JSON.NET
[Code]...
I am accessing the facebook api and using the json.net library (newtonsoft.json.net)I declare a Jobject to parse the content and look for the specific elements and get their values. Everything works fine for the first few but then I get this unexplained nullexception error " (Object reference not set to an instance of an object)Now I took a look at the declaration but cannot see how to change it. Dim jobj as JObject = JObject.Parse(responseData) message = jobj("message").tostring
The error occurs at the last line above.I check to see if message is null and then look for the next desired field as follows
[Code]...
This is one example where "message" does not appear in the first few lines but appears later. So what I do is look for position of message and description and which ever is first go and get that and if I get an error or the fields do not return anything, I try and parse by regex and even that is not working right.
I am attempting to parse some json I am getting back from a service.For example it's returning
[Code]...
parsing a JSON from a URL... Using the Nascar JSON file I am trying to place it into a listview or treeview. Displaying the drivers name, number and current position.
[Code]...
I'm new at JSON and i am currently struggling with a problem parsing JSON data in a list of objects.The data that i am trying to parse is generated by the facebook graph api, and looks like this :
{
"100001621071794": {
"id": "100001621071794",
"name": "TEST1",[code].....
I know that this is not an array, because it is missing '[' and ']'. But when i replace the '{' and '}' with '[' and ']' i'm getting an error because of an invlaid matrix.
How can I convert a JSON string to an array OR a JSON string to XML in VB.NET? I know how to do this in C#, as I have read dozens of articles on it, however, I am unable to figure out how to achieve the same result in VB.NET.
I'm using the System.Web.Script namespace via System.Web.Extensions.dll (from Microsoft).
I'm willing to use an additional DLL file if needed.
I have the following code which serialize an array to json:
Dim col1 As New ArrayList
Dim col2 As New ArrayList
objJSONStringBuilder = New StringBuilder()
objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString"))
objSQLCommand = New SqlCommand("select col1, col2 from table1", objSQLConnection)
objSQLCommand.Connection.Open()
[Code]...
I have a json array which is formatted as follows:
[Code]...
How can I deserialize this in such a way that I can have a list of objects indexed by property? Meaning, I want to be able to access the data like this: MyList(96).lastproperty or MyList(96).listofstuff.yetanother and have it return the proper datatype too? Is that even possible in vb.net?
I need to pass back a JSON result for a routine I am working with. How can I encode an Array I created to JSON? I am writing this in VB.net
View 4 RepliesHow to create this JSON array using vb.net array [code]...
View 1 RepliesI'm having problems deserializing some json data, getting InvalidCastExceptions and the like.
Can anyone point me in the right direction?
Here's the json i'm wanting to deserialize;
[{"OrderId":0,"Name":"Summary","MaxLen":"200"},{"OrderId":1,"Name":"Details","MaxLen":"0"}]
Here's my code;
[Code]...
I have "Form Designer" web application, in which I need to post the controls of the new form to an ASP.Net page to insert to DB, each time I create form control. I push it into two dimensional array, when user click save, this array will be serialized and sent to Server Page using Ajax.
Array string After Serialization Looks Like :
[
[
[code].....
I am attempting to deserialize a simple JSON array to .NET objects using the JSON.NET library in visual basic.
For the life of me, I cannot figure out what I am doing wrong here. My JSON string deserializes into appropriate objects (9 in total), but none of the properties are populated.
My code:
Public Class result
Public Property id As Integer
Public Property vote_percentage As String
[Code]....
When using JSON.NET you have to have constructor methods (i.e. Sub New) in order for the properties to get set during the Deserialization call.
I'm using a web service programmed in Visual Basic .NET 3.5 to receive a JSON Array sent from other application.
I'm sending a JSON string like this one:
[{"idRecoleccion":1,"PIN":"553648138"},{"idRecoleccion":2,"PIN":"553648138"}]
And I'm receiving the code in Visual Basic .NET as follows:
[code]...
I have worked out how to pass my custom objects into ASP.Net json webservices. Works a charm. Problem I am having is passing in straight arrays of my custom objects or alternatively passing in arrays that are parameters of my custom objects. So for example...
Public Class WebService1
Inherits System.Web.Services.WebService
<WebMethod()> _
[code]....
Fails with error: The value "System.Collections.Generic.Dictionary`2[System.String,System.Object]" is not of type "WebApplication1.WebService1+Person" and cannot be used in this generic collection. Parameter name: value
So how do I explain to ASP.net that it is infact an array of Person? note: That changing the function to as List(of Person) or ArrayList does work but given that I implement my own custom collections this is not optimal for me.
UPDATE: Ok so what I have worked out so far is that this problem is definitely associated with how the JavascriptSerializer uses the SimpleTypeResolver to resolve types. Basically if I do something like this
Public Function AddPersonList(ByVal PersonList As String) As PersonList
I can recreate the error using the following code.
Dim PersonList As PersonList = jsonSerializer.Deserialize(Of PersonList)(PList)
However when I provide my own custom type resolver along the lines of
Dim jsonSerializer As New JavaScriptSerializer(New MyCustomTypeResolver)
I can successfully create an instance of my custom list.Now I have worked out how to provide my own custom convertor in the web.config file. Along the lines of this....
<system.web.extensions>
<scripting>
<webServices>
[code]....
PSS: I have tried to use the assembly fully qualified name as specified in the docs for the SimpleTypeResolver (SimpleTypeResolver MSDN) but this throws a "Operation is not valid due to the current state of the object." exception - which is an error caused when the TypeResolver cannot resolve the name?
My problem was never passing in a List(of Object) into my webservice (I simply posed the question as such to simplify it for stackoverflow). In such a case I would be willing to completely accept using a Generic List(of) but my problem was actually that one of my custom objects implemented a property with a strong typed List(of) so for example:
Customer {CustomerID AS Guid, FirstName AS String, LastName AS String, EmailAddresses AS EmailAddressList}
which now needs to be changed to
Customer {CustomerID AS Guid, FirstName AS String, LastName AS String, EmailAddresses AS List(Of EmailAddress)}
This is admittedly not the end of the world and is probably better in the webservice context (as you have suggested) but definitely a detriment when it comes to internal application usage of my Collection properties. What this means is that once I have this property I either need to cast it to my CustomCollectionList every time I want to use some advanced feature or I need to implement another property which exposes the CustomCollectionList.
I am trying to deserialize a JSON string that looks like so: {'type':'clientlist','client_list':[]} I am using JavaScriptSerializer() to do it. For some reason the JavaScriptSerializer() is choking on the member 'client_list'. It doesn't give very good info. The error it gives is:
[Code]...
I have a table with a Int PK column and a name. I want to load them into an object of some sort and return them using Json() ActionResult in MVC 2. I am having a hard time finding a built-in structure that is supported for serialization that keeps a simple key/value structure in tact.
Ultimately I would like to do something like:
Function JsonList() As ActionResult
Dim Things = New Dictionary(Of Integer, String)
[code].....
I am been stuck on this for 3 days now...I have been accessing the twitter api to pull a user_timeline for a list of users and the json that comes back is impossible to work with. I tried to deserialize it using javascriptserializer and get an error:invalid object passed in , ':' or '}'
Now this is frustrating since I expect the json being returned to be error free. Then I tried json.net and split the posts using string.split and tried to convert each post to Jobject or jarray. for Jarray I get
'unexpected end of content while loading jArray
[Code]...
Now I have formatted the code here and not pasted the whole file but it does look like valid json to me and I do not alter anything after receiving the stream from the twitter api. Can someone please point me in the right direction? I really need to get this stuff parsed?
I'm strugling the whole day with the next JSON string
{
"0":{"link":"afbeeldingenplaatje1.jpg"},
"1":{"link":"afbeeldingenplaatje2.jpg"},
"2":{"link":"afbeeldingenplaatje3.jpg"}
}
How can i deserialize this? What's wrong with the next code (vb.net)
Public Class DataString
Private m_link As String
Public Property link() As String
Get
[CODE]...
It returns always an empty result.
how to receive and send back json. Hope someone can help me on this. I understand by examples.
On my clientside, I am sending a ajax json string "name":"theName" to the server side and would like the server side to return a string saying "welcome &name ".
Client-side code
<!DOCTYPE html>
<html>
[Code]....
Below is my JSON formated String
{"AliasName": "ysiCountryInfo", "DataClass": {"Description":"United States 111","Code":"usa","WriteOffTaxPointAdjustment":0,"IndexationRounding":6}}
I would like to deserialize object into below class
[code].....
I have a string array (strValues()) that holds a large quantity of character data. I need to parse out characters that follow "*PN" and end with "*". I then need to store this data in a datatable so that I can loop through it afterwards and pull out the unique records to be added to an existing dataset. I've been trying to use basic "IndexOf" to get started but it tells me "Overload resolution failed because no accessible 'IndexOf' accepts this number of arguments". Is there a way to accomplish what I'm trying to do?Sample data: MS50*CF3224205*PNineed/thisdata*SD07JAN10*ED21JAN10
View 4 RepliesI have a JSON response from a web service that I need to be converted to an object then to an array. My response is similar to the one below:
{"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[code]....
I am doing this is VB.NET within a console for now. Basically I am trying to create a simple way to test my API calls and output the information. What I am trying to accomplish is having to loop through the JSON array and list the stations.
I have data formatted as an ASCII text file with easting, northing, and depth fields. I've attempted an arrayList with some success, but there has to be a better and more efficient approach.
[Code]...
I've been working on this challenge for a while now without much luck. What I'm attempting to do is split a MIME byte response into its individual images. I am given the boundary to split on in the HTTP header but when I attempt the following code it doesnt work.
'boundary to split on
Dim boundary as string = _
"boundarystring"
[Code]....
unordered text file of 3 columns to assign into 2 arrays. I've been given a graphing component which expects a two dimensional array for a scatter graph for the set of values in the last column.
How would I parse through the list given an indexed array of 215 possible 'zone alarm locations' and if an alarm log list item, of which there can more than one for any given zone location, compare in the two dimensional array any previous value and replace it with the higher valued one? The following are my declarations for the 2 arrays. It isn't clear to me why the array for the scatter data was defined as (999,1) knowing there are only 215 possible x values (alarm zone locations)
[Code]...
I'm sure this has been asked before but I'm not finding quite the information I'm needing so I thought I'd post this.
I've written a PHP script that returns a simple JSON object that looks like this:
{"status":"success","level":"admin"}
I'm doing a standard web request that submits the required data to the script over the internet and that's working fine.
Now, I want to use JSON.NET to pull out the individual variables so I can know what the values of "status" and "level" are. The problem is, I have no idea where to start.
I'm doing this in VB.NET (on the .NET Compact Framework).
I would like to be able to parse vb.net code files, so I can examine the collection of Subs, Functions (and their contents, including comments), private variables, etc. I can be open the actual source code files. So for example, if I have:
[Code]....
I'm creating a vb.net winforms application that will take in user given strings, parse them, and print out labels with variable information. The given string will be used in all the labels, but the variable part of the string will change with each label.
My question is: is it better to parse the strings one time, then store those values in arrays, or to parse the string each time a label is printed? Which will perform better? Which is better practice? What is the proper way to test something like this?
I have two experimental web services. One is an asmx contained within a .net web application. The other is a WCF service library being invoked from the web application.The asmx basically does everything I need, but I think WCF would be better, except that it doesn't do anything as I would expect after fiddling with the asmx service.For example, the same method behaves differently in each:
' ASMX
<WebMethod(BufferResponse:=True, EnableSession:=False)>
Function Test(aObject as Object) as Object
' object will have been successfully serializaed into a dictionary
[code]...