JavaScriptSerializer(Resolved)

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

JavaScriptSerializer(Resolved)

Post by hallsofvallhalla »

So I am wroting a asp.net site for work and I need to convert a C# array to a javascript array as I am using C# to query the DB but using Google Charts. Using the JavaScriptSerializer class is a little silly and whom ever wrote it should be kicked in the jimmy. Anyone know a better way?
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: JavaScriptSerializer

Post by hallsofvallhalla »

ah ha! I am using .net 2.0 due to limitations on server so that is why i am having issues

I went with just turning it into a string then splitting it out :P
c#

Code: Select all

 string javascriptArray = "";
            for (int i = 0; i < DialTime.Length; i++)
            {
                javascriptArray = javascriptArray + "," + DialTime[i];
            }
javascript

Code: Select all

 var SQLDATA = '<%= javascriptarray %>';
    var DialTime = SQLDATA.split(',');
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: JavaScriptSerializer

Post by Chris »

Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: JavaScriptSerializer

Post by Jackolantern »

Oh ok! I was going to say that I believe .NET 3.5 and up can do this automatically lol.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: JavaScriptSerializer

Post by hallsofvallhalla »

Y eah i am on 2.0 and building this site from scratch. Uploading 150k entries a day then running reports on all the data. fun stuff.
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: JavaScriptSerializer

Post by Jackolantern »

I still love .NET. It is a great platform, even if MS sometimes puts silly roadblocks in the way that just seem to make some things harder (setup is often one of those). Even though node is going splendidly for me and I am really liking it, I still want to check out SignalR sometime.
The indelible lord of tl;dr
User avatar
a_bertrand
Posts: 1537
Joined: Mon Feb 25, 2013 1:46 pm

Re: JavaScriptSerializer

Post by a_bertrand »

First of all, if you are building a long string use StringBuilder not the string class. That would be MUCH faster.
To come back to the question, all depends how complex is your object tree. If it's just like a single array, you could very well do the JSON by hand. I do remember there was also a try involving web services which was producing JSON strings. I will check back if I have some code left using it.

Finally, why not try instead to produce an XML file (where C# can generate it since nearly .NET 1)? As JS can decode it without too much efforts.
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Jackolantern
Posts: 10893
Joined: Wed Jul 01, 2009 11:00 pm

Re: JavaScriptSerializer

Post by Jackolantern »

Thats a good point. XML was the world's darling back when .NET first came out, and it has great, effortless support for it :cool:
The indelible lord of tl;dr
User avatar
a_bertrand
Posts: 1537
Joined: Mon Feb 25, 2013 1:46 pm

Re: JavaScriptSerializer

Post by a_bertrand »

Like the XML serializer ;-)
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: JavaScriptSerializer

Post by hallsofvallhalla »

Thanks for all the tips and suggestions.
Post Reply

Return to “Advanced Help and Support”