Tagged Questions
26
votes
12answers
13k views
PHP json_encode encoding numbers as strings
I am having one problem with the PHP json_encode function. It encodes numbers as strings (e.g. array('id' => 3 becomes "{ ["id": "3", ...) When js encounters these values, it interprets them as ...
12
votes
1answer
29k views
Encoding Javascript Object to Json string
I want to encode a javascript object into a json string and I am having considerable difficulties.
The Object looks something like this
new_tweets[k]['tweet_id'] = 98745521;
new_tweets[k]['user_id'] ...
7
votes
3answers
7k views
Backbone: Create collection from JSON
I'm attempting to load JSON (from php's json_encode) into a Backbone JS collection. I've simplified the problem to:
var myJSON = '[{ "id":"1","name":"some name","description":"hmmm"}]';
var ...
6
votes
4answers
9k views
PHP json_encode and javascript functions
I need to encode a javascript function into a JSON object in PHP.
This:
$function = "function(){}";
$message = "Hello";
$json = array(
'message' => $message,
'func' => ...
5
votes
1answer
4k views
json_encode adding unwanted slashes
Hello all
I have a json string saved in my db. When i retrieve it from db to pass it to the javascript function (ajax call) , along with the id of that row, i am json_encoding both (the query result ...
4
votes
2answers
708 views
json_encode return undefined
My script returns undefined value from my json_encode php
index.php
<?php
$returnThis['user'] = "Robin098";
$returnThis['id'] = "08465";
echo json_encode($returnThis);
?>
...
4
votes
1answer
691 views
XSS : Creating a javascript object using PHP's json_encode
Is this 100% safe against XSS?
If not, can you please provide example bad string text showing me why it is not.
<html>
<body>
<script>
<?php
$bad = "some bad ...
3
votes
6answers
936 views
PHP json_encode encode a function
How to encode a javascript function in PHP ? I want to encode the callback function with array
$options = array(
'title' => 'Title',
'fnCallback' => someCallback);
equivalent ini javascript
...
3
votes
3answers
151 views
When should Content-Type be application/json
My server is sending data to the client.
header('Content-type: application/json');
echo json_encode($jsondata);
What is the benefit of the header? It encodes the data, but doesn't appear to have ...
3
votes
1answer
144 views
How to execute json decode in live server?
I am currently working in google map API.In google map API, i am fetching longitude and latitude from specific address.
Here is the code:
...
2
votes
1answer
884 views
JSON and whitespaces in identifiers
Question: The JavaScript code below:
records is JSON serialized data.
I can access it right away from JavaScript by using for example
alert(records.data[0].Phone);
The problem now is that some ...
2
votes
4answers
781 views
JSON Encode/decode doesn't work as it should
I am preparing and sending a JSON string from my PHP file to my Javascript function like this:
$json = array();
$json['slice'] = false;
$json['G500'] = false;
$json['KG1'] = false;
$encoded = ...
2
votes
2answers
187 views
Json string to a js array
I have a set of result which i have converted to Json using php json_encode function now i want this result as an array in js but I am not getting an idea to do this.
My PHP array is like this :
...
2
votes
3answers
5k views
how to get data to javascript from php using json_encode?
I am trying to map traceroutes to google maps.
I have an array in php with traceroute data as
$c=ip,latitude,longitude, 2nd ip, its latitude, longitude, ....target ip, its lat, its lng
I used ...
2
votes
3answers
233 views
Assigning identifier/name to JSON object in PHP
I'm grabbing data from a mysql database and encoding a JSON object with PHP to use in JS.
On the PHP end, I did this
while($row = mysql_fetch_array($result))
{
$jmarkers = array(
...