json

Loop through Json object

I have a JSON object like the following var p = { "p1": "value1", "p2": "value2", "p3": "value3" }; Now I want to loop through all p elements (p1,p2,p3...) and get their key and values. How can I do that? I can modify the Json object if necessary . My ultimate goal is to loop through some key value pa...

Delivering json content to different browser types using restlet

We have developed a RESTful webservice using the restlet framework. The service is called by ajax requests using Prototype and/or Scriptaculous (I'm not familiar with those libraries, so excuse if any of these mentioned are not accurate). Everything seems to work for most of the popular browsers, i.e. Opera, Firefox, Safari all work fin...

ASP.NET MVC: How to create an action filter to output JSON?

My second day with ASP.NET MVC and my first request for code on SO (yep, taking a short cut). I am looking for a way to create a filter that intercepts the current output from an Action and instead outputs JSON (I know of alternate approaches but this is to help me understand filters). I want to ignore any views associated with the acti...

json_decode returns NULL (php)

There is a strange behaviour with json_encode and json_decode and I can't find a solution: My php application calls a php web service. The webservice returns json that looks like this: var_dump($foo): string(62) "{"action":"set","user":"123123123123","status":"OK"}" now I like to decode the json in my application: $data = json_dec...

How to return specific date format as JSON in Grails?

In Grails, you can use the JSON converters to do this in the controller: render Book.list() as JSON The render result is [ {"id":1, "class":"Book", "author":"Stephen King", "releaseDate":'2007-04-06T00:00:00', "title":"The Shining"} ] You can control the output date by make a setting in Config.groovy grails.converters.json.dat...

Security issue with dynamic script tags

This flickr blog post discusses the thought behind their latest improvements to the people selector autocomplete. One problem they had to overcome was how to parse and otherwise handle so much data (i.e., all your contacts) client-side. They tried getting XML and JSON via AJAX, but found it too slow. They then had this to say about load...

How to parse nested JSON objects with JSON framework and Objective-C/iPhone/Xcode?

I'm writing an iPhone native app using the JSON framework. My app is accessing web services using JSON. The JSON data we send has nested objects, below is an example of the data served up: {"model":{"JSONRESPONSE":{"authenticationFlag":true,"sessionId":"3C4AA754D77BFBE33E0D66EBE306B8CA","statusMessage":"Successful Login.","locId":1,"us...

How do I add a property to a Javascript Object using a variable as the name?

I'm pulling items out of the DOM with JQuery and want to set a property on an object using the id of the DOM element. For example: obj = {}; jQuery(itemsFromDom).each(function() { element = jQuery(this); name = element.attr("id"); value = element.attr("value"); //Here's the problem obj.name = value; }); If "itemsFromDom" in...

Multidimensional Arrays and jQuery's getJSON

I am submitted a getJSON request to a controller in my application, this controller is returning valid JSON with 2 "applications." I know this for a fact as if I move the alert statement to within jQuery's each function it will give me the expected result. I am attempting to store this data within a multidimensional array to later be us...

JSON posting, am i pushing JSON too far?

Im just wondering if I am pushing JSON too far? and if anyone has hit this before? I have a xml file: <?xml version="1.0" encoding="UTF-8"?> <customermodel:Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:customermodel="http://customermodel" xmlns:personal="http://customermodel/personal" id="1" age="1" name="Joe"> <...

URL encode a non-value pair in Python

I'm trying to use Google's AJAX (JSON) Web Search API in Python. I'm stuck because Python's urllib.urlencode() only takes value pairs, not strings by themselves, to encode. In Google's API, the query string is the search term and it doesn't associate with a variable. query = "string that needs to be encoded" params = urllib.urlencode(qu...

iPhone reverse geolocation help

Hi All, I'm pretty new to iPhone SDK and Coca dev. I'd like to know how to call a web service which will take the lat and long values from my iPhone and feed them to a webservice so I can retrieve the City,State. I already have the phone location stuff squared away. I'm only looking for where I should pass this info to and how I can pars...

Replacing item databound with jquery ajax calls

Hi, We have a very slow ASP.NET page with a repeater. It is slow because most of the processing is done in the ItemDataBound event of the repeater. All this processing just gets 2 totals to be shown in each row. To increase the throughput, it could be a good idea to load the repeater without ItemDataBound event and without the 2 totals...

Python JSON decoding performance.

I'm using the json module in Python 2.6 to load and decode JSON files. However I'm currently getting slower than expected performance. I'm using a test case which is 6MB in size and json.loads() is taking 20 seconds. I thought the json module had some native code to speed up the decoding? How do I check if this is being used? As a com...

Use GZIP, JSON responses and JQuery

However, I want to compress my responses with GZIP wheren possible. I tried using the Compression filter code available for free download in the headfirst site. It works great for html, images, css and javascript. I post the filter next. It checks if GZIP is an accepted encoding and it adds gzip as Content-Encoding. See: wrappedResp.se...

Is CouchDB best suited for dynamic languages?

I´m in touch with CouchDB and the idea of mapping its results to Scala objects, as well as find some natural way to iteract with it, came immediatly. But I see that Dynamic languages such as Ruby and Javascript do things very well with the json/document-centric/shchema-free aproach of CouchDB. Any good aproach to do things with Couch i...

Comet Javascript error

I'm using Orbited as a Comet server on localhost. It is listening to ports: 9000 for http 61613 for stomp My JavaScript debugger is reporting error: JSON is not defined in the line: var vals = JSON.parse(payload); What could be the cause and how do I resolve this issue? ...

How to send JSON back with JAVA?

I am having problems using Gzip compression and JQuery together. It seems that it may be caused by the way I am sending JSON responses in my Struts Actions. I use the next code to send my JSON objects back. public ActionForward get(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse r...

Javascript 'Namespaces' and jQuery AJAX

I'm using the recommendations laid down here (http://www.odetocode.com/articles/473.aspx) to write a JavaScript AJAX webchat system using simulated Namespacing and prototyping. In one of my prototype methods I'm calling the $.ajax method in jQuery. What I then want to do is pass the returned JSON data into a method inside my JavaScript ...

JSON.stringify() bizarreness

Hello, I'm trying to figure out what's gone wrong with my json serializing, have the current version of my app with and old one and am finding some surprising differences in the way JSON.stringify() works (Using the JSON library from json.org). In the old version of my app: JSON.stringify({"a":[1,2]}) gives me this; "{"a":[1,2]}" ...