Skip to main content

Posts

Showing posts with the label json

PHP/JSON-jquery pagination

I Need away to show two per page, and have a pagination at the bottom of the page. Here is how I am currently doing it. As you can see we dont do any pagination at the moment. PHP code which returns the JSON data public function realcashoffers($state,$count) { $this->state = $state; $this->number = $count; $result = $this->JSONselect("approved_business, business_stores, Real_Cash_Offers"," *, group_concat(offer ORDER BY offer ASC SEPARATOR ',') as offers"," approved_business.id = business_stores.business_id AND Real_Cash_Offers.business_id = approved_business.id AND Real_Cash_Offers.storeid = business_stores.storeid AND business_stores.state = '{$this->state}'","GROUP BY id ORDER BY RAND(), approved_business.id DESC LIMIT {$this->number} "); $remaining = $count - count($result); if ($remaining) { $this->type = 'G'; $result = array_merge($result, $this->JSONselect("iN

How to get json data from a file (jQuery)

Just cant figure it out. I have a large object stored as a JSON file and I want to access it once and use it multiple times: var myjson = new Object(); $.getJSON("myJSON.js", function(json) { myjson = JSON.stringify(json); }); $('#console').append(myjson); This does nothing. It's a scope issue, I know. I just don't know how to do what I'm wanting. Must I do all my functions inside the $.getJSON call or is there a way to pass the object that I can use throughout runtime?

Pulling data from Google Calendar on Android in JSON

I'm using Android SDK level 8, Java. I have an app with a WebView and I want to import JSON in it. What I want to achieve is: Send HTTP requests to the Google Calendar API v3 and receive data in raw JSON, however, authenticating the request using the Android account manager. I've been looking at the GData Java Client, more specifically at the Calendar Android Sample , which authenticates properly, but I want to specifically avoid the following things: Using the GData API - unacceptable since I want a raw JSON string. Pulling the data directly through JavaScript in the WebView - unacceptable since I would want to implement a SyncProvider in Java to update the JSON string I found some information about the issue, for example: http://code.google.com/p/google-api-java-client/wiki/AndroidAccountManager com.google.gdata.client.GoogleService.setUserToken(android.accounts.AccountManager.getAuthToken(???)) However, all the examples are connected with GData. On the ot

How to nest objects when building JSON with JSONObject

I'm trying to encode this string for a POST request. Can anyone tell me how I can encode {"jsonrpc": "2.0", "method": "Files.GetSources", "params":{"media":"music"}, "id": 1} So far I have JSONOjbect obj = new JSONObject(); obj.put("jsonrpc", "2.0"); obj.put("method", "Files.GetSources"); But I'm not sure how to put in the rest - can anyone help?

dynamic key in JSON file (used by backbone.js models for example…)

I am trying to create a backbone.js model with dynamic keys but can't seem to get it done right. Here's my model: window.MyModel = Backbone.Model.extend({ myDynamicVar : "country", urlRoot: "api/myModel", defaults: { "id": null, this.myDynamicVar : "USA", "country": { "route":"test/test/test", "class":".usa2", "txt":"USA 2" }, "region": "California", "year": "", "description": "", "picture": "" } }); Here I am trying to have myDynamicVar replaced by its content in my model. Any thought how I could get this done? Thanks in advance, Jimmy

Why does JSON.stringify screw up my datetime object?

{ id: 1533, story_type_id: 1, content_id: 470, created_at: Sun, 05 Feb 2012 07:02:43 GMT, updated_at: Sun, 05 Feb 2012 07:02:43 GMT, type_name: 'post' } I have a JSON object with the "datetime" field like above. It's perfect. But when I stringify it (I want to store it in cache), I get this format: "created_at":"2012-02-05T07:02:43.000Z" This causes problems, because when I want to JSON.parse this, suddenly it's no longer datetime format and it's incompatible with my other format. What can I do to solve this problem? I have 'created_at' littered everywhere throughout my application. I don't want to manually change each one.

JSON PHP data returning null

i am trying to fetch a PHP script using AJAX and return the values as JSON. For some reason, my script fails and i am trying to figure out the problem. When i enter a value form the database into the address bar, like www.someaddress/post.php?kinaseEntry=aValue i get a json out put like so; {"kinaseSKU":null,"url":null,"molecularWeight":null,"tracerSKU":null,"antiSKU1":"antiSKU1","antiSKU2":"antiSKU2","bufferSKU":"bufferSKU","tracerConc":null,"assayConc":null} My php file looks like so; <?php //Include connection to databse require_once 'connect.php'; $kinase = mysql_real_escape_string ($_POST["kinaseEntry"]); mysql_query('SET CHARACTER SET utf8'); $findKinase = "SELECT * FROM kbaData where cleanSKU = '" .$kinase. "' "; if ($result = mysql_query($findKinase)) { $row = mysql_fetch_arra

Recursively traverse object in Objective-C

I'm converting diverse JSON objects to structured objects and want to iterate over all the nodes to process each one hierarchically. JSON framework supports conversion to an NSDictionary, which I thought was unstructured. I want to recursively iterate through each item and pay respect to the structure. How would this be done with either a dictionary or generic NSOBject? Example: - (void) processParsedObject:(NSDictionary *)obj { if (atTheEndOfTheTail) { NSLog(@"Object description: %@\n\n", obj.description); } for (id object in obj) { [self processParsedObject:object]; } } Update: I asked the question more clearly here (with answer): Recursively traverse NSDictionary of unknown structure

Omit repeated values in mysql query so the json file has only one of each

This is the query part of my json.php which is the source file of my jquery ui autocomplete input $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends $qstring = "SELECT nombre as value FROM ingredientes WHERE nombre LIKE '%".$term."%'"; $result = mysql_query($qstring);//query the database for entries containing the term while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values { $row['value']=htmlentities(stripslashes($row['value'])); //$row['id']=(int)$row['id']; $row_set[] = $row;//build an array } echo json_encode($row_set);//format the array into json data The problem is that file my return result as: [{"value":"one"},{"value":"one"},{"value":"ones"},{"value":"ona"}] So the word will be suggested twice. How can I prevent that?

Uncaught type error : Cannot read value "name" of undefined

Actually I am having a global JSON, when I am trying to parse its value in loop, it is showing me error "uncaught type error : Cannot read value 'name' of undefined". I have tried a lot but I am still not able to figure out any solution for it. $(document).ready(function(){ var productJSON = [ {id:"1001",name:"Hopper1",image:"images/290161k.jpg"}, {id:"1002",name:"Hopper2",image:"images/290161k.jpg"}, {id:"1003",name:"Hopper3",image:"images/290161k.jpg"}, {id:"1004",name:"Hopper4",image:"images/290161k.jpg"}, {id:"1005",name:"Hopper5",image:"images/290161k.jpg"}, {id:"1006",name:"Hopper6",image:"images/290161k.jpg"}, {id:"1007",name:"H

The json encode did not return response after calling the function of fb post to wall

I have a link which posted data to another page vote.php through jquery. When I click on that link, it return the state according to the condition. If that user posted the vote before then it displayed the "already voted" other wise "Your vote posted". All was working fine. I am using the facebook post to wall sdk. Now when I call the fb_publish_on_wall function from the vote.php, the message successfully posted to my fb wall but it did not return the state of the vote like "Your vote posted". What is the problem. When I comment out that line where I am calling the fb_publish_on_wall function then It works fine. I think the jquery did not get response from vote.php after calling the fb_publish_on_wall function. How will I fix this? UPDATED: Here is the fb_publish_on_wall function function fb_publish_on_wall($message,$link,$picture,$name,$description,$user_facebook2) { $message = str_replace(array('<br />', '<

Why do I keep getting "undefined" for each item in this JSON array?

The following is returning 'undefined' as the value for each item. Can someone show me why? Jquery $("button").click(function () { var estimateID = this.id; var baseURL = "/Dashboard/EstimateDetails/"; var url = baseURL + estimateID; $.getJSON(url, function (data) { for (var i = 0; i <= data.details.length; i++) { $('#Details').html("<p>item1=" + data.details.Dma + " item2=" + data.details.Callsign + " item3=" + data.details.Description + "</p>"); } }); JSON { "details": [{ "Dma": "Albany-Schenectady-Troy", "CallSign": "WRGB", "Description": "WRGB (CBS) Schenectady" }, { "Dma": "Albany-Schenectady-Troy", "CallSign": "WTEN", "Description": "WTEN (ABC) Albany "

JSON parse with jquery?

I could use some help with the syntax when using jquery to parse this json data coming back from the server. I have tried several examples from stackoverflow and other sites and for some reason I keep getting undefined as the out put instead of the id numbers. Each one should be its own line. { "ROWCOUNT":7, "COLUMNS":["ID"], "DATA":{"id":"211","212","213","221","222","223","232"]} }

Open new tab in Chrome extensions

I'm trying to write a simple google extension that will upon clicking "ctrl+alt+x" search for the selected text in google. This is my mainfest: { "name": "A jQuery Chrome extension", "version": "0.1", "description": "Use jQuery to build Chrome extensions", "content_scripts": [ { "matches" : ["http://*/*"], "js": ["jquery.js", "jquery.hotkeys.js", "content.js"] } ], "background_page": "background.html", "permissions": [ "tabs" ] } And this is my content.js: $(document).bind('keydown', 'alt+ctrl+x', function() { var selectedText = window.getSelection().toString(); if (selectedText) { var googleQuery = "http://www.google.com/search?q=" + selectedText; alert(googleQuery); chrome.tabs.create({"url

JSON data is not parsed?

I followed the advice here on how to use JSON. After using $resultAml = json_encode($resultArray); in PHP I get this at the client: [{"id":"1","0":"1","title":"Facebook","1":"Facebook","url":"http://facebook.com","2":"http://facebook.com","domain":"facebook.com","3":"facebook.com","tag":"","4":""},{"id":"1","0":"1","title":"Ideeli","1":"Ideeli","url":"http://www.ideeli.com","2":"http://www.ideeli.com","domain":"ideeli.com","3":"ideeli.com","tag":"web","4":"web"},{"id":"1","0":"1","title":"Kikin","1":"Kikin"