json

Parsing JSON Payload in Rails When Using Custom MIME Type

A Rails application with a RESTful interface needs to accept POST data using a custom MIME type based on 'application/json'. Let's call that MIME type 'application/vnd.com.example.Foo+json'. Registering the custom MIME type in Rails using Mime::Type.register works fine in that the application recognizes the MIME type given in the "Accep...

Deserializing variable Type JSON array using DataContractJsonSerializer

I have a JSON string in this form: string jsonStr = "[\"A\", [\"Martini\", \"alovell\"],[\"Martin\", \"lovell\"]]" I am trying to deserialize the JSON using the C# .NET deserializer DataContractJsonSerializer with the following code snippet MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonStr)); DataContractJsonSerializ...

Using Wiki API by format JSON can't get the content.

I use this code to gathering the information from Wiki: http://en.wikipedia.org/w/api.php?action=query&rvprop=content&prop=revisions&format=json&titles=apple And I can get a JSON String like this { "query": { "normalized": [{ "from": "apple", "to": "Apple" }], "pa...

Remove a JSON attribute

if I have a JSON object say: var myObj = {'test' : {'key1' : 'value', 'key2': 'value'}} can I remove 'key1' so it becomes: {'test' : {'key2': 'value'}} ...

How do you JSON serialize a set of hidden input values (jQuery can be used)?

I have the following DOM structure.. <input id="WorkAssignmentID_3462" type="hidden" value="3462" name="WorkAssignmentID"/> <input id="WorkItemID_3462" type="hidden" value="3633" name="WorkItemID"/> <input id="EmployeeID_3462" type="hidden" value="15" name="EmployeeID"/> <input id="AssignedBy_3462" type="hidden" value="Jonathan Erickson...

What are some best practices for dynamically adding javascript in an asp.net page?

This is actual code from what I am working on that takes an ID from the query string, retrieves an object and parses to json. I am going to need to store and manipulate this data client-side. What is the best way to set the generated json string to a client-side object? Note: NewObjectCase is a class with the method Get(strID) that retu...

How to return the correct content-type for JSON in CakePHP?

Hi, I'm trying to set the content-type header for a JSON response accessed with an AJAX GET request. I've followed tutorials on blogs and the bakery but I always receive 'text/html' back from CakePHP. How do I set the content-type header correctly? Here's my code at the moment: http://bin.cakephp.org/view/668011600 Any help would be ap...

How to force requests to be JSON? I.e. how to block XML body?

I have a REST WCF service and a WCF client application for it. My operation has the WebGet attribute with the following properties: BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json However, when I use the WCF client, the request is made with the body in XML format! This...

Yahoo Boss getJson

Anyone know how to do a JSON call to the Yahoo Boss API? Ideally the URL for the documentation on how to do this... Thanks, Mark ...

jQuery.post() Using serialized form data, and custom object in submission.

When doing ajax stuff with jQuery you can pass your data along to the server in two key ways: Use an object like { firstname:'blah', lastname: 'derp' } Use a string like &firstname=blah&lastname=derp (1) Arises naturally when you're passing in values programatically. (2) Arises naturally when you've got input fields. My problem: it...

Returning .net Hashtable from a JQuery ajax request

I have a webmethod that returns a Hashtable through a jQuery ajax call along the lines of: $.ajax({ type: "POST", url: webMethod, data: {} contentType: "application/json; charset=utf-8", dataType: "json", success: function(json){ **alert(json.d);** }, error: function(XMLHttpRequest, textStatus, errorThrown)...

Decode complex JSON in Python

Hey, I have a JSON object created in PHP, that JSON object contains another escaped JSON string in one of it's cells: php > $insidejson = array('foo' => 'bar','foo1' => 'bar1'); php > $arr = array('a' => array('a1'=>json_encode($insidejson))); php > echo json_encode($arr); {"a":{"a1":"{\"foo\":\"bar\",\"foo1\":\"bar1\"}"}} Then, wit...

jquery decode json object with double quoted keys

I have a script that outputs a json string via json_encode in PHP. The json string consists of [{"custId":"2","custName":"John Inc"}] The PHP script is initiated using $.getJSON("customer.php", function(data){alert(data + ' ' + data.custName);}); The response is - [object Object] undefined Javascript recognises 'data' as an...

JSON: How do I alert the name of the first node in level 1 in this code snippet?

var response = "{\"tree\":[{\"level1\":[{\"node\":{\"id\": 1,\"name\": \"paradox\",\"parent\": 0}}]},{\"level2\":[{\"node\":{\"id\": 2,\"name\": \"lucent\",\"parent\": 1}},{\"node\":{\"id\": 3,\"name\": \"reiso\",\"parent\": 1}}]},{\"level3\":[{\"node\":{\"id\": 4,\"name\": \"pessi\",\"parent\": 3}},{\"node\":{\"id\": 5,\"name\": \"misho...

Using jQuery to get json data returns invalid label error

I have this code, and have also tried something similar using the $.getJson function: jQuery(document).ready(function(){ var kiva_url = "http://api.kivaws.org/v1/loans/newest.json"; jQuery.ajax({ type: "GET", url: kiva_url, data:"format=json", success: function(data){ alert("here"); jQuer...

jQuery - parsing JSON data - Having trouble with variable name

My first delve into working with JSON data. I have a bit of experience using jQuery though. I'm posting to this URL (tumblr api): jyoseph.com/api/read/json What I'm trying to do is output the json that gets returned. What I have so far: $(document).ready(function(){ $.getJSON("http://jyoseph.com/api/read/json?callback=?", functio...

[Rails] To go API or not

My company has this Huge Database that gets fed with (many) events from multiple sources, for monitoring and reporting purposes. So far, every new dashboard or graphic from the data is a new Rails app with extra tables in the Huge Database and full access to the database contents. Lately, there has been an idea floating around of having...

JSON Parse Error using Adobe Flex - PHP - SQL

I am trying to return results from my SQL database, using PHP to convert it into JSON, which is then read by Flex. Here is the parse error I receive - JSONParseError: Unexpected < encountered at com.adobe.serialization.json::JSONTokenizer/parseError()[/Users/mesh/src/as3corelib/src/com/adobe/serialization/json/JSONTokenizer.as:579] at ...

Averting Cross Domain issues with Callback functions?

I am using HTML and trying to get a JSON response from a URL. I ran in to cross domain issues. I then tried using a callback function in order to avoid this problem. When I do so, and the control passes to the function. I see a "Invalid Label" error in firebug and it shows the JSON response that i get back. When i did some reading i ...

cakephp, jquery, .ajax(), dataType: json

is it possible to be able to do without a view for a cakephp controller function? i am trying to have my server return a datatype that is not a string - but an array my controller function : function test() { $this->layout = 'plain'; $task['Numbers']['uno'] = 'mooo'; $task['Numbers']['dos'] = 'says the cow'; ...