json

C# Web Service won't output JSON, only XML

I'm trying to use jQuery and JSON with a C# Web Service that I wrote. No matter what, the following code will only output in XML. Webservice Code [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string HelloWorld() { return "Hello World!"; } I also have these attributes assigned to the class [WebServiceBin...

Why does my code return the error "missing : after property id" in JavaScript?

How is this supposed to be written so that it would actually work? saveBuyerInfo( { 'save_'+$("#textAreaXMLPostRequest").attr('name') : $("#textAreaXMLPostRequest").val() } ); ...

Parsing JSON DateTime from Newtonsoft's JSON Serializer

I've serialized an object using Newtonsoft's JSON serializer, and the DateTime has come through as: /Date(1237588418563+0000)/ When I $.evalJSON() on that, it is an object but I can't find any normal Date methods like toUTCString on it. Any ideas what I can do with this? ...

execute function on completion of another, use ajaxComplete()?

Hi there, two functions need to be executed in Javascript, the second one only after the first has finished. The first populates an array with getJSON, and the second will then manipulate it. However, getJSON is asynchronous, thus it will not pause the order of execution to make the program work properly so that the array finishes load...

convert rss to JSON

craigslist has an rss feed and i wish to convert the feed to JSON format so that I can parse it. anybody know any tool that can do this - convert craigslist rss (or any rss) to JSON format ...

Binding application/json to POCO object in asp.net mvc, Serialization exception

I'm passing json back up from my view to my controller actions to perform operations. To convert the json being sent in, to a POCO I'm using this Action Filter: public class ObjectFilter : ActionFilterAttribute { public Type RootType { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { IList<Erro...

A circular reference was detected while serializing an object of type System.Globalization.CultureInfo

I'm using jquery to call a webservice which returns a dataset with a couple of tables in it. This was working ok until i needed to set up my webmethod to accept a parameter. I reflected this on the client side with data: "{paramname:'" + paramval+ "'}", I now get the following error when the webmethod returns. This happens regardles...

What should a JSON service return on failure / error

I'm writing a JSON service in C# (.ashx file). On a successful request to the service I return some JSON data. If the request files, either because an exception was thrown (e.g. database timeout) or because the request was wrong in some way (e.g. an ID that doesn't exist in the database was given as an argument) how should the service re...

What is the correct syntax to represent subobjects in JSON?

I have a simple object that is deserialized from JSON into a server-side object. JSON: { name : 'ObjectName', host : 'http://localhost', ImagesPath : '/Images/' } On the server side, the above JSON code gets deserialized into this C# object via System.Web.Script.Serialization.JavaScriptSeriali...

Json Import fails - C#

I have the following class structure public class AreaFields { public List<Fields> Fields { set; get; } } public class Fields { public string Name { set; get; } public string Value {set; get; } } When I export to Json using Jayrock.Json.Conversion.JsonConvert.ExportToString(List<AreaField> obj), everything works fine. The...

How do I test for an empty Javascript object from JSON?

After an AJAX request, sometimes my application may return an empty object, like: var a = ({}); How can I check if that's the case? ...

Returning JSON from PHP to JavaScript?

I have a PHP script that's being called through jQuery AJAX. I want the PHP script to return the data in JSON format to the javascript. Here's the pseudo code in the PHP script: $json = "{"; foreach($result as $addr) { foreach($addr as $line) { $json .= $line . "\n"; } $json .= "\n\n"; } $json .= "}"; Basically, I...

Json <-> Java serialization that works with GWT

I am looking for a simple Json (de)serializer for Java that might work with GWT. I have googled a bit and found some solutions that either require annotate every member or define useless interfaces. Quite a boring. Why don't we have something really simple like class MyBean { ... } new GoodSerializer().makeString(new MyBean()); new...

Adding further attributes to a ActiveRecord serialization?

I have my json serialization working fine render :json => "#{current_object.serialize(:json, :attributes => [:id, :name])} But I also want to add further data to the json before it gets set back to the client. Mainly the auth_token. Googled around like crazy but I can not find what option serialize will take to allow me to append/me...

Elegant way to implement manipulating temporary storage - ASP.NET

I have a user control, on load of which I have some data from the database. A user can manipulate the data in different ways (CRUD). The process of manipulating data can cause server side events or at the client side. Then there is a save button on the page that eventually processes the temporary data and writes it to the database. I am...

How do you deal with the conflict between ActiveSupport::JSON and the JSON gem?

I am stumped with this problem. ActiveSupport::JSON defines to_json on various core objects and so does the JSON gem. However, the implementation is not the same -- the ActiveSupport version takes arguments and the JSON gem version doesn't. I installed a gem that required the JSON gem and my app broke. The issue is that I'm using to_js...

encode array to JSON in PHP to get [elm1,elm2,elm3] instead of {elm1:{},elm2:{},elm3:{}}

I am trying to json_encode an array, which is what returns from a Zend_DB query. var_dump gives: (Manually adding 0 member does not change the picture). array(3) { [1]=> array(3) { ["comment_id"]=> string(1) "1" ["erasable"]=> string(1) "1" ["comment"]=> string(6) "test 1" } [2]=> array(3) { ["comme...

Problems with encoding Json request

I try to manually build a Json string to send to the client. {'result':'hhh'} When I use echo json_encode(array('result'=>'hhh')); It arrives perfectly. But when I do echo "{'result':'hhh'}"; It isn't The only difference I find between the two requests is that the first one has: Content-Length: 9 header and the second o...

Will JSON replace XML as a data format?

When I first saw XML, I thought it was basically a representation of trees. Then I thought: the important thing isn't that it's a particularly good representation of trees, but that it is one that everyone agrees on. Just like ASCII. And once established, it's hard to displace due to network effects. The new alternative would have to...

How to quickly clear a Javascript Object?

With a Javascript Array, I can reset it to an empty state with a single assignment: array.length = 0; This makes the Array "appear" empty and ready to reuse, and as far as I understand is a single "operation" - that is, constant time. Is there a similar way to clear a JS Object? I know I can iterate its fields deleting them: for (pr...