1function IsJsonString(str) {
2 try {
3 JSON.parse(str);
4 } catch (e) {
5 return false;
6 }
7 return true;
8}
1<?php
2$jsonurl = "https://reqres.in/api/users?page=2";
3$json = file_get_contents($jsonurl);
4$jsonDecode = json_decode($json, true);
5var_dump($jsonDecode['data']);
6foreach($jsonDecode['data'] as $mydata){
7 echo $mydata['email'] . "<br>";
8}
9?>
1//code igniter
2$query="qry";
3$query = $this->db->query($query);
4$res=$query->result();
5return json_encode($res);
1$json = '
2{
3 "type": "donut",
4 "name": "Cake",
5 "toppings": [
6 { "id": "5002", "type": "Glazed" },
7 { "id": "5006", "type": "Chocolate with Sprinkles" },
8 { "id": "5004", "type": "Maple" }
9 ]
10}';
11
12$yummy = json_decode($json, true);
13
14echo $yummy['toppings'][2]['type']; //Maple
15