Search Results

Search found 5623 results on 225 pages for 'mr json'.

Page 9/225 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Rails, JSON Object, jQuery, Auto-Complete

    - by Michael Waxman
    I'm using this jquery autocomplete plug-in with rails: http://docs.jquery.com/Plugins/Autocomplete I can't figure out how to format my results, both in my Rails controller and in my javascript file. I have something like this in my controller... @query = params[:q].downcase @json = User.all(:login => /^#{@query}/) respond_to do |format| format.js { render :json => @json.to_json(:only => "login"), :layout => false } end And then this in my script.js file... $("#form").autocomplete('/url', { width: 320, dataType: 'json', highlight: false, scroll: true, scrollHeight: 300 }) But I can't figure out how to parse the data, so my autocomplete just gets a raw array of all my results at once. How do I process the JSON in the script.js file and/or in my controller for it to work?

    Read the article

  • appcelerator titanium cannot parse JSON

    - by Richard
    Hi, I'm new to titanium and get difficulty in parsing JSON from mysql export. the json is valid and I feel frustrated with many unsuccessful trials. To simplify the code, I put it below. The code just stop and said: [ERROR] Script Error = Unable to parse JSON string var win = Titanium.UI.currentWindow; var hotdealjson = "{'hotdeal':[{'place':'bangkok','date':'4D3N','cost':'$4999up'},{'place':'tokyo','date':'3D2N','cost':'$3799up'}]}"; //read json var response = JSON.parse(hotdealjson); alert(response.hotdeal.length); Thanks & regards, Richard

    Read the article

  • Asp.net JSON Deserialize problem

    - by Billy
    I want to deserialize the following JSON string: [ {"name":"photos","fql_result_set":[{"owner":"123456","caption":"Caption 1", "object_id":123},{"owner":"223456","caption":"Caption 2", "object_id":456}]}, {"name":"likes","fql_result_set":[{"object_id":123,"user_id":12156144},{"object_id":456,"user_id":140342725}]} ] and get the POCO like [DataContract] public class Photo{ [DataMember] public string owner{get;set;} [DataMember] public string caption{get;set;} [DataMember] public string object_id{get;set;} } [DataContract] public class Like { [DataMember] public string object_id { get; set; } [DataMember] public string user_id { get; set; } } What should I do? I already have this piece of code: public class JSONUtil { public static T Deserialize<T>(string json) { T obj = Activator.CreateInstance<T>(); MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json)); System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType()); obj = (T)serializer.ReadObject(ms); ms.Close(); return obj; }

    Read the article

  • Converting an array to JSON and passing that to asmx

    - by user96403
    Hi. I am trying to use JSON.stringify() (from json2.js of json[dot]org ) to convert a JavaScript array to JSON string and to pass it to an asmx web method. I use jQuery AJAX. The call reaches the web method where I take a List <Object> as parameter but I get an empty list there in debug mode. My JSON string looks like well formed with all data , I even tried having single-quotes and double-quotes(escaped) around the 'names' of the JSON string. Please help.

    Read the article

  • Why Is my json-object from AJAX not understood by javascript, even with 'json' dataType?

    - by pete
    My js code simply gets a json object from my server, but I think it should be automatically parsed and turned into an object with properties, yet it's not allowing access properly. $.ajax({ type: 'POST', url: '/misc/json-sample.js', data: {href: path}, // THIS IS THE POST DATA THAT IS PASSED IN TO THE DRUPAL MENU CALL TO GET THE MENU... dataType: 'json', success: function (datax) { if (datax.debug) { alert('Debug data: ' + datax.debug); } else { alert('No debug data: ' + datax.toSource() ) ; } The /misc/json-sample.js file is: [ { "path": "examplemodule/parent1/child1/grandchild1", "title": "First grandchild option", "children": false } ] (I have also been trying to return that object from drupal as follows, and the same results.) Drupal version of misc/json-sample.js: $items[] = array( 'path' = 'examplemodule/parent1/child1/grandchild1', 'title' = t('First grandchild option'), 'debug' = t('debug me!'), 'children' = FALSE ); print drupal_to_js($items); What happens (in FF, which has the toSource() capability) is the alert with 'No debug data: [ { "path": "examplemodule/parent1/child1/grandchild1", "title": "First grandchild option", "children": false } ] Thanks

    Read the article

  • Parsing dbpedia JSON in Python

    - by givp
    Hello, I'm trying to get my head around the dbpedia JSON schema and can't figure out an efficient way of extracting a specific node: This is what dbpedia gives me: http://dbpedia.org/data/Ceramic_art.json I've got the whole thing as a JSON object in Python but don't really understand how to get the english abstract from this data. I've gotten this far: u = "http://dbpedia.org/data/Ceramic_art.json" data = urlfetch.fetch(url=u) json_data = json.loads(data.content) for j in json_data["http://dbpedia.org/resource/Ceramic_art"]: if(j == "http://dbpedia.org/ontology/abstract"): print "it's here" Not sure how to proceed from here. As you can see there are multiple languages. I need to get the english abstract. Thanks for your help, g

    Read the article

  • Sending JSON collection to ASMX webservice

    - by Mironline
    I have got this json collection in page : var json= { "Elements": [ {"Alignment":null,"Bold":false}, {"Alignment":null,"Bold":false} ], "Front":true, "ThemeID":"9" }; I've generated this JSON in run-time & posted to page. my question is , What is the best solution to send this json to web-service using jQuery. should I use the JSON.stringify method and sent it as as string ? if yes what is the input type in web-service ? can I send it as an object to web-service and set the List<CusomeObject> as input ? in this case how can I implement that ?

    Read the article

  • ASP.NET MVC submitting json array to controller as regular post request (nonajax)

    - by j3ko
    All the examples of json I can find online only show how to submit json arrays w/ the jquery command $.ajax(). I'm submitting some data from a custom user control as a json array. I was wondering if it's possible to submit a json array as a regular post request to the server (like a normal form) so the browser renders the page returned. Controller: [JsonFilter(Param = "record", JsonDataType = typeof(TitleViewModel))] public ActionResult SaveTitle(TitleViewModel record) { // save the title. return RedirectToAction("Index", new { titleId = tid }); } Javascript: function SaveTitle() { var titledata = GetData(); $.ajax({ url: "/Listing/SaveTitle", type: "POST", data: titledata, contentType: "application/json; charset=utf-8", }); } Which is called from a save button. Everything works fine but the browser stays on the page after submitting. I was thinking of returning some kind of custom xml from the server and do javascript redirect but it seems like a very hacky way of doing things. Any help would be greatly appreciated.

    Read the article

  • basic json > struct question

    - by danwoods
    I'm working with twitter's api, trying to get the json data from http://search.twitter.com/trends/current.json which looks like: {"as_of":1268069036,"trends":{"2010-03-08 17:23:56":[{"name":"Happy Women's Day","query":"\"Happy Women's Day\" OR \"Women's Day\""},{"name":"#MusicMonday","query":"#MusicMonday"},{"name":"#MM","query":"#MM"},{"name":"Oscars","query":"Oscars OR #oscars"},{"name":"#nooffense","query":"#nooffense"},{"name":"Hurt Locker","query":"\"Hurt Locker\""},{"name":"Justin Bieber","query":"\"Justin Bieber\""},{"name":"Cmon","query":"Cmon"},{"name":"My World 2","query":"\"My World 2\""},{"name":"Sandra Bullock","query":"\"Sandra Bullock\""}]}} My structs look like: type trend struct { name string query string } type trends struct { id string arr_of_trends []trend } type Trending struct { as_of string trends_obj trends } and then I parse the JSON into a variable of type Trending. I'm very new to JSON so my main concern is making sure I've have the data structure correctly setup to hold the returned json data. I'm writing this in 'Go' for a project for school. (This is not part of a particular assignment, just something I'm demo-ing for a presentation on the language)

    Read the article

  • How to extract the actual NSString from json object as NSArray

    - by Toran Billups
    I'm working with a large set of json and really just need the NSString representation of what's inside the NSArray -including all the { } My question is this - is their a better way than simply looping through each NSArray inside the main NSArray and outputting the description one by one? ie- the below is a start to this process but it's very brittle meaning I need to know each item inside the hat {} and this isn't something I actually care about. I just need the json string to move forward. The working code is below (thank you in advance!) NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; [responseData release]; NSArray* json = [responseString JSONValue]; NSArray* item = [json valueForKeyPath:@"d.data"]; NSArray* hatjson = [item objectForKey:@"hat"]; NSMutableString * result = [[NSMutableString alloc] init]; for (NSObject * obj in hatjson) { [result appendString:[obj description]]; } NSLog(@"the hat json is .. %@", result);

    Read the article

  • Issue in accessing JSON object?

    - by Esh
    Am facing issue in accessing the JSON object : JSON Object am receiving is : {"71":"Heart XXX","76":"No Heart YYYY"} I tried to get the value of 71 and 72 separately and use it ... but am getting some compile time issue as : Syntax error on token ".71", delete this token Code: var map=$("#jsonText").val(); alert(map); var obj=jQuery.parseJSON(map); alert("JSON ::"+obj.71); If am printing obj , am able to view [Object Object] Can any one out there please help me to find the mistake i did ..I know the question above is asked in many threads in SO . Below are the few threads i found , but failed when i attempted to implement it .. jquery json parsing Also tried using the Jquery tutorial given in Jquery JSON Its working fine if the key is a String but getting the above error if its a number ...

    Read the article

  • Is this a correct json format....

    - by chandru_cp
    I want to get a fair idea about json format... I am using php in which i have converted my result array to json like this $result = mysql_query("select dStud_id,dMarkObtained1,dMarkObtained2, dMarkObtained3,dMarkTotal from tbl_internalmarkallot"); $JsonVar = json_encode($res); echo "<input type='text' name='json' id='json' value ='$JsonVar'>"; And the text box shows {"0":"101","dStud_id":"101","1":"60","dMarkObtained1":"60","2":"80", "dMarkObtained2":"80","3":"80","dMarkObtained3":"80","4":"220","dMarkTotal":"220"} Is this a correct json format....

    Read the article

  • Get Python 2.7's 'json' to not throw an exception when it encounters random byte strings

    - by Chris Dutrow
    Trying to encode a a dict object into json using Python 2.7's json (ie: import json). The object has some byte strings in it that are "pickled" data using cPickle, so for json's purposes, they are basically random byte strings. I was using django.utils's simplejson and this worked fine. But I recently switched to Python 2.7 on google app engine and they don't seem to have simplejson available anymore. Now that I am using json, it throws an exception when it encounters bytes that aren't part of UTF-8. The error that I'm getting is: UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0: invalid start byte It would be nice if it printed out a string of the character codes like the debugging might do, ie: \u0002]q\u0000U\u001201. But I really don't much care how it handles this data just as long as it doesn't throw an exception and continues serializing the information that it does recognize. How can I make this happen? Thanks!

    Read the article

  • How do I parse this JSON with jQuery?

    - by Mike
    So I had this structure in xml and I was able to parse it successfully. Now what I have done is that I converted this xml into a JSON using www.xmltojson.org but I am not able to parse it . I am setting these files locally on we localhost web server: <script> $(function() { $.ajax({ url:'feed.json', dataType:'json', type:'GET', success:function(json) { /// what to do here }. error: { alert("Parse Failed"); } }); }); </script> I am trying to learn JSON, so I am little unsure as to where I am doing wrong, or even if that is the correct approah. Thanks Mikey.

    Read the article

  • The *right* JSON content type?

    - by Oli
    Right I've been messing around with JSON for some time, just pushing it out as text and it hasn't hurt anybody (I know of), but I'd like to start doing things properly. I have seen so many purported "standards" for the JSON content type: application/json application/x-javascript text/javascript text/x-javascript text/x-json But which is right? Or best? I gather that there are security and browser support issues varying between them... (I know there's a similar question, What MIME type if JSON is being returned by a REST API?, but I'd like a slightly more targeted answer.)

    Read the article

  • Convert JSON data into String

    - by san6086
    Hi I am converting JSON data into String. Please find the JSON data below. I am facing an issue where in the system is unable to convert NULL values into string. Therefore, I am getting the following error: can't convert nil into String (TypeError) JSON DATA: {"success":true,"message":null,"data":null} Code Used: c = Curl::Easy.new(Configuration.fetch("<URL where we can find the above JSON DATA and nothing else>")) # c.follow_location = true # c.http_auth_types = :basic # c.username = Configuration.fetch('auth_user', false) # c.password = Configuration.fetch('auth_pass', false) # c.headers["User-Agent"] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17' # c.perform result=JSON.parse(c) puts result["Success"] Please help.

    Read the article

  • Combine multiple JSON files into one; retrieve using jQuery/getJSON()

    - by frankadelic
    I have some jQuery code which retrieves content using getJSON(). There are n JSON files, which are retrieved from the server as needed: /json-content/data0.json /json-content/data1.json /json-content/data2.json etc... Instead, I want to store all the JSON in a single file to reduce the number of HTTP requests needed to retrieve the data. What is the best way to do this? If I concatenate the JSON files together, it no longer works with getJSON(). I would prefer not to transform the JSON data ahead of time, as it is coming from a third party data source. Any suggestions?

    Read the article

  • Byte array serialization in JSON.NET

    - by Daniel Earwicker
    Given this simple class: class HasBytes { public byte[] Bytes { get; set; } } I can round-trip it through JSON using JSON.NET such that the byte array is base-64 encoded: var bytes = new HasBytes { Bytes = new byte[] { 1, 2, 3, 4 } }; // turn it into a JSON string var json = JsonConvert.SerializeObject(bytes); // get back a new instance of HasBytes var result1 = JsonConvert.DeserializeObject<HasBytes>(json); // all is well Debug.Assert(bytes.Bytes.SequenceEqual(result1.Bytes)); But if I deserialize this-a-wise: var result2 = (HasBytes)new JsonSerializer().Deserialize( new JTokenReader( JToken.ReadFrom(new JsonTextReader( new StringReader(json)))), typeof(HasBytes)); ... it throws an exception, "Expected bytes but got string". What other options/flags/whatever would need to be added to the "complicated" version to make it properly decode the base-64 string to initialize the byte array? Obviously I'd prefer to use the simple version but I'm trying to work with a CouchDB wrapper library called Divan, which sadly uses the complicated version, with the responsibilities for tokenizing/deserializing widely separated, and I want to make the simplest possible patch to how it currently works.

    Read the article

  • Ruby JSON.pretty_generate ... is pretty unpretty

    - by Amy
    I can't seem to get JSON.pretty_generate() to actually generate pretty output in Rails. I'm using Rails 2.3.5 and it seems to automatically load the JSON gem. Awesome. While using script/console this does indeed produce JSON: some_data = {'foo' => 1, 'bar' => 20, 'cow' => [1, 2, 3, 4], 'moo' => {'dog' => 'woof', 'cat' => 'meow'}} some_data.to_json => "{\"cow\":[1,2,3,4],\"moo\":{\"cat\":\"meow\",\"dog\":\"woof\"},\"foo\":1,\"bar\":20}" But this doesn't produce pretty output: JSON.pretty_generate(some_data) => "{\"cow\":[1,2,3,4],\"moo\":{\"cat\":\"meow\",\"dog\":\"woof\"},\"foo\":1,\"bar\":20}" The only way I've found to generate it is to use irb and to load the Pure version: require 'rubygems' require 'json/pure' some_data = {'foo' => 1, 'bar' => 20, 'cow' => [1, 2, 3, 4], 'moo' => {'dog' => 'woof', 'cat' => 'meow'}} JSON.pretty_generate(some_data) => "{\n \"cow\": [\n 1,\n 2,\n 3,\n 4\n ],\n \"moo\": {\n \"cat\": \"meow\",\n \"dog\": \"woof\"\n },\n \"foo\": 1,\n \"bar\": 20\n}" BUT, what I really want is Rails to produce this. Does anyone have any tips why I can't get the generator in Rails to work correctly? Thanks! Updated 5:20 PM PST: Corrected the output.

    Read the article

  • Is parsing JSON faster than parsing XML

    - by geme_hendrix
    I'm creating a sophisticated JavaScript library for working with my company's server side framework. The server side framework encodes its data to a simple XML format. There's no fancy namespacing or anything like that. Ideally I'd like to parse all of the data in the browser as JSON. However, if I do this I need to rewrite some of the server side code to also spit out JSON. This is a pain because we have public APIs that I can't easily change. What I'm really concerned about here is performance in the browser of parsing JSON versus XML. Is there really a big difference to be concerned about? Or should I exclusively go for JSON? Does anyone have any experience or benchmarks in the performance difference between the two? I realize that most modern web developers would probably opt for JSON and I can see why. However, I really am just interested in performance. If there's a proven massive difference then I'm prepared to spend the extra effort in generating JSON server side for the client.

    Read the article

  • Deserializing a complex JSON result (array of dictionaries) with TouchJSON

    - by jpm
    I did a few tests with TouchJSON last night and it worked pretty well in general for simple cases. I'm using the following code to read some JSON content from a file, and deserialize it: NSString *jsonString = [[NSString alloc] initWithContentsOfFile:@"data.json"]; NSData *jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding]; NSError *error = nil; NSDictionary *items = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; NSLog(@"total items: %d", [items count]); NSLog(@"error: %@", [error localizedDescription]); That works fine if I have a very simple JSON object in the file (i.e. a dictionary): {"id": "54354", "name": "boohoo"} This way I was able to get access to the array of values, as I wanted to get the item based on its index within the list: NSArray *items_list = [items allValues]; NSString *name = [items_list objectAtIndex:1]; (I understand that I could have fetched the name with the dictionary API) Now I would like to deserialize a semi-complex JSON string, which represents an array of dictionaries. An example of such a JSON string is below: [{"id": "123456", "name": "touchjson"}, {"id": "3456", "name": "bleh"}] When I try to run the same code above against this new content in the data.json file, I don't get any results back. My NSLog() call says "total items: 0", and no error is coming back in the NSError object. Any clues on what is going on? I'm completely lost on what to do, as there isn't much documentation available for TouchJSON, and much less usage examples.

    Read the article

  • jQuery DataTables: Problems with POST Server Side JSON output

    - by Tim
    Hello Everyone, I am trying to get my datatable to take a POST JSON output from my server. This is my client side code <script> $(document).ready(function() { $('#example').dataTable( { "bProcessing": true, "bServerSide": true, "sAjaxSource": "http://localhost/staff/jobs/my_jobs", "fnServerData": function ( sSource, aoData, fnCallback ) { $.ajax( { "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback } ); } } ); } ); </script> Now I have copied and pasted the server side code found in the DataTables examples found here. When I change my sAjaxSource to view this page the table doesn't move beyond 'processing'. When I view the JSON directly I see this output. {"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["Trident","First Ever Job"]] } Just for fun I went to the POST server-side example and copied some of the JSON they are using for their example and just PHP echoed it straight out of another page. This is the output of that page. {"sEcho": 1, "iTotalRecords": 1, "iTotalDisplayRecords": 1, "aaData": [ ["Trident","Internet Explorer 4.0"]] } Here is where it gets interesting. The JSON that has been processed by the server fails to work yet the JSON simply echo'd by the same server on a different page does work... yet both are almost identical in outputs. I hope someone can shed some light on this because as the tree said to the lumberjack... I'm stumped. Thanks, Tim

    Read the article

  • JSON and Microformats

    - by Tauren
    I'm looking for opinions on whether microformats should be used to name JSON elements. For instance, there is a microformat for physical addresses, that looks like this: <div class="adr"> <div class="street-address">665 3rd St.</div> <div class="extended-address">Suite 207</div> <span class="locality">San Francisco</span>, <span class="region">CA</span> <span class="postal-code">94107</span> <div class="country-name">U.S.A.</div> </div> There is a document available on using JSON and Microformats. The information above could be represented as JSON data like this: "adr": { "street-address":"665 3rd St.", "extended-address":"Suite 207", "locality":"San Fransicso", "region":"CA", "postal-code":"94107", "country-name":"U.S.A." }, The issue I have with this is that I'd like my JSON data to be as lightweight as possible, but still human readable. While still supporting international addresses, I would prefer something like this: "address": { "street":"665 3rd St.", "extended":"Suite 207", "locality":"San Fransicso", "region":"CA", "code":"94107", "country":"U.S.A." }, If I'm designing a new JSON API right now, does it make sense to use microformats from the start? Or should I not really worry about it? Is there some other standard that is more specific to JSON that I should look at?

    Read the article

  • asp.net mvc outputting json with backslashes ( escape) despite many attemps to filter

    - by minus4
    i have an asp.net controller that output Json as the results a section of it is here returnString += string.Format(@"{{""filename"":""{0}"",""line"":[", file.Filename); what i get returned is this: "{\"DPI\":\"66.8213457076566\",\"width\":\"563.341067\",\"editable\":\"True\",\"pricecat\":\"6\",\"numpages\":\"2\",\"height\":\"400\",\"page\":[{\"filename\":\"999_9_1.jpg\",\"line\":[]},{\"filename\":\"999_9_2.jpg\",\"line\":[]}]]" i have tried to return with the following methods: return Json(returnString); return Json(returnString.Replace("\\",""); return Json will serialize my string to a jSon string, this i know but it likes to escape for some reason, how can i get rid of it ???? for info this is how i call it with jQuery: $.ajax({ url:"/Products/LoadArtworkToJSon", type:"POST", dataType: "json", async: false, data:{prodid: prodid }, success: function(data){ sessvars.myData = data; measurements = sessvars.myData; $("#loading").remove(); //empty the canvas and create a new one with correct data, always start on page 0; $("#movements").remove(); $("#canvas").append("<div id=\"movements\" style=\"width:" + measurements.width + "px; height:" + Math.round(measurements.height) + "px; display:block; border:1px solid black; background:url(/Content/products/" + measurements.page[0].filename + ") no-repeat;\"></div>"); your help is much appreciated thanks

    Read the article

  • JSON Twitter List in C#.net

    - by James
    Hi, My code is below. I am not able to extract the 'name' and 'query' lists from the JSON via a DataContracted Class (below) I have spent a long time trying to work this one out, and could really do with some help... My Json string: {"as_of":1266853488,"trends":{"2010-02-22 15:44:48":[{"name":"#nowplaying","query":"#nowplaying"},{"name":"#musicmonday","query":"#musicmonday"},{"name":"#WeGoTogetherLike","query":"#WeGoTogetherLike"},{"name":"#imcurious","query":"#imcurious"},{"name":"#mm","query":"#mm"},{"name":"#HumanoidCityTour","query":"#HumanoidCityTour"},{"name":"#awesomeindianthings","query":"#awesomeindianthings"},{"name":"#officeformac","query":"#officeformac"},{"name":"Justin Bieber","query":"\"Justin Bieber\""},{"name":"National Margarita","query":"\"National Margarita\""}]}} My code: WebClient wc = new WebClient(); wc.Credentials = new NetworkCredential(this.Auth.UserName, this.Auth.Password); string res = wc.DownloadString(new Uri(link)); //the download string gives me the above JSON string - no problems Trends trends = new Trends(); Trends obj = Deserialise<Trends>(res); private T Deserialise<T>(string json) { T obj = Activator.CreateInstance<T>(); using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json))) { DataContractJsonSerializer serialiser = new DataContractJsonSerializer(obj.GetType()); obj = (T)serialiser.ReadObject(ms); ms.Close(); return obj; } } [DataContract] public class Trends { [DataMember(Name = "as_of")] public string AsOf { get; set; } //The As_OF value is returned - But how do I get the //multidimensional array of Names and Queries from the JSON here? }

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >