blogspot visit counter

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

2 comments:

  1. Thank you for your information.it is very nice article.
    .NET Online Training Hyderabad

    ReplyDelete
  2. Casino Slots - DrmCMD
    Casino Slots. A 전주 출장마사지 list of casino games, including slots, 김해 출장안마 jackpots, video poker, video 포천 출장안마 bingo, scratch cards and live dealer tables 서울특별 출장샵 for 양주 출장마사지 American players.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...