How to convert JSON string to PHP objects

in #utopian-io6 years ago (edited)

JSON

Json is one kind of java script object notation. Where open standard designed for data interchange of human- readable. Json file extension we can write this .json. This tutorial help people how Json uses in other language. Such as php, java, python etc. Json is also uniform type identifier in public .json. Its uses in web services and also in APIs. All are used this because Json is easy to read and write than other. Its also independent. So everyone can work and get suitable to use Json in language.

Here we learn about Json develop format in data interchange. After completing this tutorial we also know java, ajax etc, how to use it.

What is the requirement to learn Json

At first you should know the basic knowledge of web application's work just like HTTP and also want to know java script.

Difficulty of Json work

All are know about the level of work. Such as basic, intermediate and advanced. So it's defend on you how to know about java script properly. You know hard so you can easily work at advanced level otherwise basic level or intermediate level.

How to use JSON in PHP

Here we know about how to encode and decode Json using Php language. At first want to know Json functions and works.
json_encode works like Josn value return.
json_decode works in Json string to decode.

Example of JSON string how to use to store information-

And the program are code as json.htm-

So its a JSON code and how to use to store. Now how to encode and decode Json toPhp objects notation.

Encoding JSON to PHP

In Php using this function json_encode() for encoding Json to Php.

Syntax using-

        string json_encode ($value [, $options = 0])

parameter using-

        This function only works UTF-8 data. And also value being encoded.
         And also consisting optional value such as JSON_HEX_QUOT, JSON_HEX_APOS, JSON_HEX_AMP, JSON_FORCE_OPJECT etc.

Example of JSON to PHP

How to convert array into JSOn with PHP-

##And see the result like that-

##So how to PHP objects converted into JSON-

##And the following results-

Decoding JSON to PHP

In Php using this function json_decode() for decoding Json to Php.

Syntax using-

                      mixed json_decode ($json [, $assoc = false [, depth = 512 [, options = 0 ]]])

Parameter using-

                     It also an encoded string where UTF=8 data encoded.
                     It's an integer type number where parameter recursion depth.
                     It's an bitmask Json integer type such as Json Decode and Json_BIGINT_AS_String are 
                     supported.

Example of how to decode Json to Php objects

And the result -



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

Your contribution doesn't appear to be about utopian.io

You can contact us on Discord.
[utopian-moderator]

@safat
Your publication has been successfully shared, with more than 2398 Steemit users thank you for participating in the last edition of free reestem.
If you find my project useful, donate a vote to my comment

This post received a 1% upvote from @morwhale team thanks to @safat! For more information, click here! , TeamMorocco! .
STEEM Price : 4.287 $ ID : 1516455120000

Coin Marketplace

STEEM 0.18
TRX 0.13
JST 0.029
BTC 56855.37
ETH 2976.87
USDT 1.00
SBD 2.39