Javascript - JSON Array Type Resolution In ASP.Net Webservices?

Jan 6, 2011

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.

View 5 Replies


ADVERTISEMENT

JavaScript Serialize Array To JSON?

Mar 28, 2011

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].....

View 2 Replies

Convert JSON To Array OR JSON To XML?

Jul 17, 2011

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.

View 1 Replies

Javascript - .Net Json Serialization Format?

May 16, 2012

I was hoping someone may be able to point me in the right direction in regards to the format of a Json.I've never really worked with Json's and Serialization before so it's all a little new.I need to return a Json from .Net in the following format.[[Date.UTC(2011,12,14,8), 8], [Date.UTC(2011,12,14,9), 1]]

I'm almost there but am struggling with the format of my string, as by default the string is quoted. This is what I have:

[Code]...

View 2 Replies

Javascript - Return JSON From ASP.NET .asmx?

Nov 5, 2009

I have the following test method:Imports System.Web

Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _

[Code]...

Even with the ResponseFormat attribute added the response is still being returned as XML rather than JSON.

View 6 Replies

Javascript - Create A Json Object In 2005?

Sep 8, 2009

I want to create a json object in vb.net to send the response back javascript function to do something?

View 2 Replies

Javascript - Pass JSON File From ASP.NET To JQuery?

Feb 27, 2012

my problem is that my company does not want to serve up the .json MIME type, so I have to use ASP.NET to fetch the JSON file from the file server. Currently I have jQuery that does a getJSON and traverses the JSON object to build certain elements of the page. Is there a way I can use ASP.NET (VB) to give the object to my jQuery script after I fetch it?

View 1 Replies

Javascript - Accessing Elements Of JSON Object Without Knowing The Key Names

Feb 25, 2011

Here's my json:

{"d":{"key1":"value1",
"key2":"value2"}}

Is there any way of accessing the keys and values (in javascript) in this array without knowing what the keys are?

The reason my json is structured like this is that the webmethod that I'm calling via jquery is returning a dictionary. If it's impossible to work with the above, what do I need to change about the way I'm returning the data?

Here's an outline of my webmethod:

<WebMethod()> _
Public Function Foo(ByVal Input As String) As Dictionary(Of String, String)
Dim Results As New Dictionary(Of String, String)

[Code]....

View 2 Replies

Asp.net - Serialize Array To Json?

Jun 23, 2011

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]...

View 2 Replies

Deserialize Json Array In .net?

Feb 1, 2011

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?

View 2 Replies

Encode An Array To JSON?

Feb 23, 2009

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 Replies

Parsing A JSON Array?

May 6, 2011

I'm trying to parse this array using JSON.NET

[Code]...

View 1 Replies

Create JSON Array Using Program?

Mar 5, 2012

How to create this JSON array using vb.net array [code]...

View 1 Replies

Deserializing Json Array Into .net Class?

Feb 16, 2010

I'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]...

View 3 Replies

VS 2008 - User Can Retrieve Value In Any Numeric Array Type Rather Than Specifying An Array Type

Aug 11, 2011

I am writing a scripting language which used .net for execution. Now I have written a function which accepts an object and return a set of numeric values. I wanted user to pass any numeric array (e.g. integer,single,double,long) and I could return values in that format. I mean user can retrieve value in any numeric array type rather than specifying an array type. E.g.

[Code]...

View 15 Replies

Deserialize A Simple JSON Array To .NET Objects?

Feb 3, 2012

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.

View 1 Replies

Receive JSON Array As Argument In Web Service?

Jul 6, 2010

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]...

View 1 Replies

Make Program What Work In Any Type Of Resolution And Monitor?

Jun 22, 2010

I want to know how can I make a program what will work in any type of resolution & monitor. For example if I make an application fullscreen it will work. But problem is that text boxes or another things will not work properly. For example if I make a program & make it fullscreen for 1440 * 900 resolution it will work fine when it will get 1440 * 900 resolution. But when it will get different resolution like 1280 * 1024 or something like that it will make my application fullscreen but buttons or another things will not be present there in same place. So what should I do to get rid of this problem? All I want to make a program what will adjust itself everywhere(though you change resolution or monitor like 17 inch or 29 inch whatever it will work & buttons & another thinks will be there in same place).

View 1 Replies

Json - JavaScriptSerializer() Deserializing Dictionary Array Members

Dec 4, 2011

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]...

View 1 Replies

Make A MVC 2 Json Serializable Structure With Apropriate PK Array Keys?

Jan 1, 2010

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].....

View 1 Replies

Twitter Json - Unable To Convert To Jobject Or Jarray Using Json.net / Javascriptserializer?

May 9, 2012

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?

View 1 Replies

JSON.NET Deserialize - Next JSON String - Returns Always An Empty Result

Feb 21, 2011

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.

View 1 Replies

Receiving Json And Send Back Json On Server-side?

Jul 28, 2011

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]....

View 2 Replies

Deserializing JSON Into Byrefrence ParametrizedConstructor Object With Json?

Nov 12, 2010

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].....

View 1 Replies

Convert JSON String To JSON Object?

Jan 18, 2012

I 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.

View 3 Replies

Get List Of All Resolution Of Client Monitor And Check With Resolution Passed By Application?

Dec 5, 2009

How to get list of all resolution of client monitor and check with resolution passed by application

View 2 Replies

Make An Application Look As Though It Has Been Set To A Screen Resolution Of 1024 X 768 When The True Resolution Different?

Oct 2, 2009

1. Is there anyway to make an application look as though it has been set to a screen resolution of 1024 x 768 when the true resolution different?

2. I am developing my app using a widescreen monitor. What dimensions does the form need to be set to so that it looks exactly the same on a normal & widescreen monitor?

View 1 Replies

Screen Resolution - Change The Size On The Form And The Button When Its Ran On A Different Resolution

Oct 22, 2007

I am working on an program and I need it to change the size on the form and the button etc when its ran on a different resolution then it was coded on. Is there anyway to do this easy or do I have to hard code it on two different and change it by like a button etc? I am working with a 1024 X 780 and a 1240 X 1024.

View 8 Replies

Change Resolution Of Form Based On Screen Resolution

Jan 10, 2011

I have a very high screen resolution on my laptop: 1400x1050.My colleague tried it out on his laptop (which had lesser resolution), and the application did not fit on his laptop. The buttons were dragging out of the screen space.So, I want my application to automatically resize/adjust based upon the screen resolution.I don't want to use Maximized screen option and don't want to change user's pc settings.Unfortunatly I am not using Table Layout panel.

View 5 Replies

Change User Control Resolution According To Screen Resolution?

Dec 29, 2010

In my application,I placed the user control on a panel,I want to resize that control on a panel automatically according to different screen resolution.

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved