blogspot visit counter
Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Monday, 28 October 2013

Json with integer in php

Json with integer in php
Introduction :-
Here i am explain how to use  PHP  json_encode function.

In some cases numeric data may  appear as numeric strings, for example 1 as "1". While consuming the json data on a client app that would mean an extra parsing to get for example an int from the string.

The solution is to simply use an extra option (JSON_NUMERIC_CHECK) on the json_encode function call:

then you will not get the data in string format.You get the data like 1 without double quotes

use for json_encode
   



<?php echo json_encode($data, JSON_NUMERIC_CHECK); ?>

For example

{"data":[{"x":0,"y":0,"username":"%s","gender":"%s","location":"%s","id":"%s","age":30},{"x":0,"y":0,"username":"Ranvijay Singh","gender":"male","location":"Navi Mumbai (New Mumbai), India","id":1179445904,"age":30},{"x":10,"y":20,"username":"aman","gender":"male","location":"indore","id":123,"age":30}]}


Here x and y is integer values then not show double quotes
Related Posts Plugin for WordPress, Blogger...