Why is there an error in myJson structure? - php

I'm trying to correct my json but I still have some errors, I did use a Json Editor but it didn't help me to understand what is the error
I don't know if it has a one more open '{' in my code or does it miss a ',' ?
It seems the error is on line 79 but I don't know exactly what is not correct exactly..
{
"data": [{
"Contact_Name": {
"id": "1884053000034678068"
},
"Subject": "1 - XKBKNABJK",
"Status": "Sans Impact Stock",
"Entity": "",
"Etat": "CM - Annul\u00e9",
"Invoice_Date": "2017-11-21",
"Discount": 0.000000,
"Tax": ["TVA"],
"Total_HT": "55.000000",
"Total_TVA": 0,
"Methode_de_paiement": "Payment by check",
"ID_Lip": "1",
"Origine": "CM",
"Type_de_Facture": "Solde",
"Transporteur": "My carrier",
"Reference_Colis": "",
"Billing_Street": "16, Main street",
"Compl_ment_Facturation": "2nd floor",
"Billing_City": "Miami",
"Billing_Country": "\u00c9tats-Unis",
"Billing_Code": "33133",
"Shipping_Street": "16, Main street",
"Compl_ment_Livraison": "2nd floor",
"Shipping_City": "Miami",
"Shipping_Country": "\u00c9tats-Unis",
"Shipping_Code": "33133",
"Product_Details": [{
"product": {
"id": "1884053000030235273"
},
"Product_Name": "Blouse - Color : White, Size : M",
"list_price": 22.5,
"quantity": 1,
"Discount": 0,
"Discount_Amount": 0,
"line_tax": [{
"percentage": 20,
"name": "TVA"
}]
}, {
"product": {
"id": "1884053000030235273"
},
"Product_Name": "Printed Dress - Color : Orange, Size : S",
"list_price": 21.67,
"quantity": 1,
"Discount": 0,
"Discount_Amount": 0,
"line_tax": [{
"percentage": 20,
"name": "TVA"
}]
}, {
"product": {
"id": "1884053000012868763"
},
"list_price": 1.67,
"quantity": 1,
"Discount": 0,
"Discount_Amount": 0,
"line_tax": [{
"percentage": 20,
"name": "TVA"
}]
}],
"Adjustment": 0,
"Montant_TPH": 0,
"TVA_sur_DEEE_TPH": "0",
"Taxes_DEEE_TPH": "TPH",
"Frais_de_port_HT": "2.000000",
"Frais_de_port_TTC": "2.000000",
"Nb_produits": 3,
"Quantite_totale": 3
}]
}
Thank you very much for your help!

Related

The avalara JSON request not working using PHP cURL but working in postman

I have created a JSON for avalara request, line items are 10 in count. But it is always showing error as -
code:ErrorCountLimitExceededError
number:1722
message : The request has exceeded the maximum number of validation errors.
When I reduce the line item to count 6, it works fine. but my requirement is more than that.
The same JSON is working fine in postman.
Following is the JSON which I had used-
{
"lines": [
{
"number": "1",
"quantity": 1,
"amount": 100,
"taxCode": "PS081282",
"itemCode": "Y0001GHGH",
"description": "TEST"
},
{
"number": "2",
"quantity": 1,
"amount": 100,
"taxCode": "PS081282A",
"itemCode": "TTTTYYYA",
"description": "TEST"
},
{
"number": "3",
"quantity": 1,
"amount": 190,
"taxCode": "PS081282B",
"itemCode": "HGHGHG0001B",
"description": "TEST"
},
{
"number": "4",
"quantity": 1,
"amount": 2300,
"taxCode": "PS081282C",
"itemCode": "PKOO0001C",
"description": "TEST"
},
{
"number": "5",
"quantity": 1,
"amount": 200,
"taxCode": "PS081282D",
"itemCode": "ABCF567",
"description": "TEST"
},
{
"number": "6",
"quantity": 1,
"amount": 10990,
"taxCode": "PS081282E",
"itemCode": "Y00DSD01E",
"description": "TEST"
},
{
"number": "7",
"quantity": 1,
"amount": 140,
"taxCode": "PS081282F",
"itemCode": "Y00GJG232",
"description": "TEST"
},
{
"number": "8",
"quantity": 1,
"amount": 100,
"taxCode": "PS081282F2X",
"itemCode": "65HGFH675",
"description": "TEST"
}
],
"type": "SalesInvoice",
"companyCode": "DEFAULT",
"date": "2023-01-10",
"customerCode": "ABC",
"purchaseOrderNo": "2023-01-10-001",
"addresses": {
"singleLocation": {
"line1": "2000 Main Street",
"city": "Irvine",
"region": "CA",
"country": "US",
"postalCode": "92614"
}
},
"commit": true,
"currencyCode": "USD",
"description": "Yarn"
}

Display menu categories and lists all menus under each menu categories and return json data

I have the following tables
categories and menus. A category can have many menus example rice is a category that has many menus under it. I want to list all categories with their appropriate menu under each category and return json in php using pdo. Below is an example of what I mean
Soups
Booze Wings
Suya Wings
Booze Wings
Appetizer
Hot Dogs
Chinese Stir-fried Rice
Fried Rice
Below is the json format how I want it to diaplay
"categoryHeading": "Appetizer",
"menu": [
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 156,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Abacha",
"price": "300.00",
"quantity": 12,
"menu_type": "All day",
"created_at": "2020-10-28 04:31:50",
"updated_at": "2020-10-28 04:31:50",
"image_url": "/storage/foodmenuimages/foodmenimage956871603859510.jpeg",
"is_active": 1,
"description": null,
"month": "October",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 101,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Avocado Ring Salad",
"price": "3200.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 23:56:27",
"updated_at": "2020-09-27 23:56:27",
"image_url": "/storage/foodmenuimages/foodmenimage856971601232987.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 88,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Beef Burger",
"price": "2300.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 23:07:09",
"updated_at": "2020-09-27 23:07:09",
"image_url": "/storage/foodmenuimages/foodmenimage765981601230029.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 90,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Beef Quesadilla",
"price": "2200.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 23:10:48",
"updated_at": "2020-09-27 23:10:48",
"image_url": "/storage/foodmenuimages/foodmenimage659871601230248.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
"categoryHeading": "Soup",
{
"restaurant_name": "METRO CAFE",
"category_name": "Soup",
"id": 111,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Bowl chicken with Assorted Vegi",
"price": "4100.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-28 17:54:50",
"updated_at": "2020-09-28 17:54:50",
"image_url": "/storage/foodmenuimages/foodmenimage957681601297690.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Soups ",
"id": 83,
"restaurant_id": 10,
"category_id": 3,
"food_name": "Buffalo Wings",
"price": "1600.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 22:33:25",
"updated_at": "2020-09-27 22:33:25",
"image_url": "/storage/foodmenuimages/foodmenimage596781601228005.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 79,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Butterfly Prawns",
"price": "3200.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 22:23:16",
"updated_at": "2020-09-27 22:23:16",
"image_url": "/storage/foodmenuimages/foodmenimage698751601227396.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 87,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Chicken Burger",
"price": "2300.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 23:02:39",
"updated_at": "2020-09-27 23:02:39",
"image_url": "/storage/foodmenuimages/foodmenimage679851601229759.png",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 99,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Chicken Mushroom Soup",
"price": "1600.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 23:45:21",
"updated_at": "2020-09-27 23:45:21",
"image_url": "/storage/foodmenuimages/foodmenimage985671601232321.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 97,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Chicken Noodle Soup",
"price": "1900.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 23:44:02",
"updated_at": "2020-09-27 23:44:02",
"image_url": "/storage/foodmenuimages/foodmenimage659781601232242.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 91,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Chicken Quesadilla",
"price": "2200.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 23:11:12",
"updated_at": "2020-09-27 23:11:12",
"image_url": "/storage/foodmenuimages/foodmenimage768591601230272.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Soups ",
"id": 81,
"restaurant_id": 10,
"category_id": 3,
"food_name": "Chicken Springroll",
"price": "1600.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 22:26:52",
"updated_at": "2020-09-27 22:26:52",
"image_url": "/storage/foodmenuimages/foodmenimage869751601227612.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
{
"restaurant_name": "METRO CAFE",
"category_name": "Appetizer",
"id": 89,
"restaurant_id": 10,
"category_id": 1,
"food_name": "Chicken Wrap",
"price": "2200.00",
"quantity": 1,
"menu_type": "All day",
"created_at": "2020-09-27 23:08:39",
"updated_at": "2020-09-27 23:08:39",
"image_url": "/storage/foodmenuimages/foodmenimage859671601230119.jpg",
"is_active": 1,
"description": null,
"month": "September",
"year": "2020",
"chopsrestaurant_id": null,
"is_featured": 0,
"sub_heading_title": null
},
PHP Codes
public static function getMenuByRestaurantId($id)
{
$selectStatment = \DB::getPdo()->prepare("SELECT r.restaurant_name, c.category_name, m.* from menus as m
inner join restaurants as r on r.id = m.restaurant_id inner join categories as c on c.id = m.category_id where m.restaurant_id = :restaurant_id order by m.food_name asc");
$selectStatment->bindValue(':restaurant_id', $id, \PDO::PARAM_STR);
$selectStatment->execute();
$results = $selectStatment->fetchAll(\PDO::FETCH_OBJ);
return $results;
}
JSON I am trying to return
$menu = DTO::getMenuByRestaurantId($id);
foreach($menu as $m)
{
$heading = $m->category_name;
}
return response()->json(["categoryHeading"=>$heading, "menu" =>$menu], 200);

Why does Json_encode return an empty array? [duplicate]

This question already has answers here:
Why does json_decode return null for empty array?
(5 answers)
Closed 3 years ago.
Here is ths json I'm using :
{
"data": [{
"Contact_Name": {
"id": "1884053000034678068"
},
"Subject": "1 - XKBKNABJK",
"Status": "Sans Impact Stock",
"Entity": "",
"Etat": "CM - Annul\u00e9",
"Invoice_Date": "2017-11-21",
"Discount": 0.000000,
"Tax": ["TVA"],
"Total_HT": "55.000000",
"Total_TVA": 0,
"Methode_de_paiement": "Payment by check",
"ID_Lip": "1",
"Origine": "CM",
"Type_de_Facture": "Solde",
"Transporteur": "My carrier",
"Reference_Colis": "",
"Billing_Street": "16, Main street",
"Compl_ment_Facturation": "2nd floor",
"Billing_City": "Miami",
"Billing_Country": "\u00c9tats-Unis",
"Billing_Code": "33133",
"Shipping_Street": "16, Main street",
"Compl_ment_Livraison": "2nd floor",
"Shipping_City": "Miami",
"Shipping_Country": "\u00c9tats-Unis",
"Shipping_Code": "33133",
"Product_Details": [{
"product": {
"id": "1884053000030235273"
},
"Product_Name": Blouse - Color: White,
Size: M,
"list_price": 22.5,
"quantity": 1,
"Discount": 0,
"Discount_Amount": 0,
"line_tax": [{
"percentage": 20,
"name": "TVA"
}]
}, {
"product": {
"id": "1884053000030235273"
},
"Product_Name": Printed Dress - Color: Orange,
Size: S,
"list_price": 21.67,
"quantity": 1,
"Discount": 0,
"Discount_Amount": 0,
"line_tax": [{
"percentage": 20,
"name": "TVA"
}]
}, {
"product": {
"id": "1884053000012868763"
},
"list_price": 1.67,
"quantity": 1,
"Discount": 0,
"Discount_Amount": 0,
"line_tax": [{
"percentage": 20,
"name": "TVA"
}]
}],
"Adjustment": 0,
"Montant_TPH": 0,
"TVA_sur_DEEE_TPH": "0",
"Taxes_DEEE_TPH": "TPH",
"Frais_de_port_HT": "2.000000",
"Frais_de_port_TTC": "2.000000",
"Nb_produits": 3,
"Quantite_totale": 3
}],
"duplicate_check_fields": ["ID_Lip"],
"trigger": []
}
But when I use the json_encode() function it doesn't return me an object json but simply an empty array, and I don't see any syntax error in the code too. I don't know if it's really a syntax error or something else.. Can someone helps me know what/where is the problem ?
Thank you in advance!
There is an error in the syntax of your json near to "Product_Name".
The values ​​must be strings and therefore between "".
Tell us if you have resolution problems :)
Have a good day !
Solution
Use json_decode($jsondata, true) instead.
detailed explanation: json_decode
Propper JSON to use
Also there is a error in your json-string
Here is the propper json to use:
{
"data": [{
"Contact_Name": {
"id": "1884053000034678068"
},
"Subject": "1 - XKBKNABJK",
"Status": "Sans Impact Stock",
"Entity": "",
"Etat": "CM - Annul\u00e9",
"Invoice_Date": "2017-11-21",
"Discount": 0.000000,
"Tax": ["TVA"],
"Total_HT": "55.000000",
"Total_TVA": 0,
"Methode_de_paiement": "Payment by check",
"ID_Lip": "1",
"Origine": "CM",
"Type_de_Facture": "Solde",
"Transporteur": "My carrier",
"Reference_Colis": "",
"Billing_Street": "16, Main street",
"Compl_ment_Facturation": "2nd floor",
"Billing_City": "Miami",
"Billing_Country": "\u00c9tats-Unis",
"Billing_Code": "33133",
"Shipping_Street": "16, Main street",
"Compl_ment_Livraison": "2nd floor",
"Shipping_City": "Miami",
"Shipping_Country": "\u00c9tats-Unis",
"Shipping_Code": "33133",
"Product_Details": [{
"product": {
"id": "1884053000030235273"
},
"Product_Name": "Blouse - Color: White, Size: M",
"list_price": 22.5,
"quantity": 1,
"Discount": 0,
"Discount_Amount": 0,
"line_tax": [{
"percentage": 20,
"name": "TVA"
}]
}, {
"product": {
"id": "1884053000030235273"
},
"Product_Name": "Printed Dress - Color: Orange, Size: S",
"list_price": 21.67,
"quantity": 1,
"Discount": 0,
"Discount_Amount": 0,
"line_tax": [{
"percentage": 20,
"name": "TVA"
}]
}, {
"product": {
"id": "1884053000012868763"
},
"list_price": 1.67,
"quantity": 1,
"Discount": 0,
"Discount_Amount": 0,
"line_tax": [{
"percentage": 20,
"name": "TVA"
}]
}],
"Adjustment": 0,
"Montant_TPH": 0,
"TVA_sur_DEEE_TPH": "0",
"Taxes_DEEE_TPH": "TPH",
"Frais_de_port_HT": "2.000000",
"Frais_de_port_TTC": "2.000000",
"Nb_produits": 3,
"Quantite_totale": 3
}],
"duplicate_check_fields": ["ID_Lip"],
"trigger": []
}
For the future
Check your json here for secure results.
I hope this helps

Passing a serialized array using POST yields unexpected result

I am puzzled.
My goal is to pass the array through POST to another page and access it's data. I found a way of doing it using serialize().
It worked fine since I am able to see the array on the other page, but when I try to access a nested array within the main array I don't get the expected results. In other words, I can access the data inside the main array but I get "null" for the inner array.
Let me show you what I did:
//The array:
$cart = &JModelLegacy::getInstance('cart', 'jshop');
$cart->load();
//I can access data of the inner array (the products) within the $cart array, for example:
$productos = $cart->products;
echo "<pre>".json_encode($cart, JSON_PRETTY_PRINT)."</pre>";
echo "<pre>".json_encode($productos[1], JSON_PRETTY_PRINT)."</pre>";
//Then serializing it:
$serializedcart = serialize($cart);
//Then sending it in a form using POST
<input type='hidden' name='cartserialized' value='<?php print $serializedcart?>'>
.... then on the other page:
// I unserialize the transferred array:
$carretilla = unserialize($_POST[cartserialized]);
// And this doesn't work anymore, I get "null" for $productos:
$productos = $carretilla->products;
echo "<pre>".json_encode($carretilla, JSON_PRETTY_PRINT)."</pre>";
echo "<pre>".json_encode($productos[1], JSON_PRETTY_PRINT)."</pre>";
Why? Any help will be greatly appreciated.
This is the output before serialization: (Output of $cart and products inside cart.)
{
"type_cart": "cart",
"products": [
{
"quantity": 1,
"product_id": 329,
"category_id": "17",
"tax": null,
"tax_id": "0",
"product_name": "ATX Cromo Puro",
"thumb_image": "thumb_882-2.jpg",
"delivery_times_id": "0",
"ean": "882-2",
"attributes": "a:1:{i:1;i:28;}",
"attributes_value": [
{
"attr_id": 1,
"value_id": 28,
"attr": "Color",
"value": "Cromo"
}
],
"extra_fields": [],
"weight": "0.0000",
"vendor_id": "1",
"files": "a:0:{}",
"freeattributes": "a:0:{}",
"manufacturer": "Cross",
"pid_check_qty_value": "A:218",
"price": 570,
"href": "\/index.php\/tienda\/product\/view\/17\/329",
"free_attributes_value": []
},
{
"quantity": 3,
"product_id": 469,
"category_id": "21",
"tax": null,
"tax_id": "0",
"product_name": "Bater\u00eda Auxiliar",
"thumb_image": "thumb_JK-PB035.jpg",
"delivery_times_id": "0",
"ean": "JK-PB035",
"attributes": "a:0:{}",
"attributes_value": [],
"extra_fields": [],
"weight": "35.0000",
"vendor_id": "1",
"files": "a:0:{}",
"freeattributes": "a:0:{}",
"manufacturer": null,
"pid_check_qty_value": "P:469",
"price": 265,
"href": "\/index.php\/tienda\/product\/view\/21\/469",
"free_attributes_value": []
}
],
"count_product": 4,
"price_product": 1365,
"summ": 0,
"rabatt_id": 0,
"rabatt_value": 0,
"rabatt_type": 0,
"rabatt_summ": 0,
"model_temp_cart": "tempcart",
"price_product_brutto": 1365
}
{
"quantity": 3,
"product_id": 469,
"category_id": "21",
"tax": null,
"tax_id": "0",
"product_name": "Bater\u00eda Auxiliar",
"thumb_image": "thumb_JK-PB035.jpg",
"delivery_times_id": "0",
"ean": "JK-PB035",
"attributes": "a:0:{}",
"attributes_value": [],
"extra_fields": [],
"weight": "35.0000",
"vendor_id": "1",
"files": "a:0:{}",
"freeattributes": "a:0:{}",
"manufacturer": null,
"pid_check_qty_value": "P:469",
"price": 265,
"href": "\/index.php\/tienda\/product\/view\/21\/469",
"free_attributes_value": []
}
And after serialization and sending:
{
"__PHP_Incomplete_Class_Name": "jshopCart",
"type_cart": "cart",
"products": [
{
"quantity": 1,
"product_id": 329,
"category_id": "17",
"tax": null,
"tax_id": "0",
"product_name": "ATX Cromo Puro",
"thumb_image": "thumb_882-2.jpg",
"delivery_times_id": "0",
"ean": "882-2",
"attributes": "a:1:{i:1;i:28;}",
"attributes_value": [
{
"attr_id": 1,
"value_id": 28,
"attr": "Color",
"value": "Cromo"
}
],
"extra_fields": [],
"weight": "0.0000",
"vendor_id": "1",
"files": "a:0:{}",
"freeattributes": "a:0:{}",
"manufacturer": "Cross",
"pid_check_qty_value": "A:218",
"price": 570,
"href": "\/index.php\/tienda\/product\/view\/17\/329",
"free_attributes_value": []
},
{
"quantity": 3,
"product_id": 469,
"category_id": "21",
"tax": null,
"tax_id": "0",
"product_name": "Bater\u00eda Auxiliar",
"thumb_image": "thumb_JK-PB035.jpg",
"delivery_times_id": "0",
"ean": "JK-PB035",
"attributes": "a:0:{}",
"attributes_value": [],
"extra_fields": [],
"weight": "35.0000",
"vendor_id": "1",
"files": "a:0:{}",
"freeattributes": "a:0:{}",
"manufacturer": null,
"pid_check_qty_value": "P:469",
"price": 265,
"href": "\/index.php\/tienda\/product\/view\/21\/469",
"free_attributes_value": []
}
],
"count_product": 4,
"price_product": 1365,
"summ": 0,
"rabatt_id": 0,
"rabatt_value": 0,
"rabatt_type": 0,
"rabatt_summ": 0,
"model_temp_cart": "tempcart",
"price_product_brutto": 1365
}
null
In order to deserialize an object in PHP, you need to load the class first. So include the script that defines the type of this object, then deserialize.
Thank you guys.
I tried using json_encode and json_decode as suggested in other forum and it seems to work better and I have no problem sending and retrieving the data on the other end.
Thanks for your valuable time.

Catchable fatal error: php json decode

My json data
{
"total": 533489,
"page": 1,
"pagesize": 30,
"questions": [
{
"tags": [
"php",
"html",
"forms"
],
"answer_count": 6,
"favorite_count": 0,
"question_timeline_url": "/questions/22075370/timeline",
"question_comments_url": "/questions/22075370/comments",
"question_answers_url": "/questions/22075370/answers",
"question_id": 22075370,
"owner": {
"user_id": 3343981,
"user_type": "registered",
"display_name": "user3343981",
"reputation": 3,
"email_hash": "55d0eb4577a0ba9f9e428d445431b595"
},
"creation_date": 1393520772,
"last_activity_date": 1393522799,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 48,
"score": 0,
"community_owned": false,
"title": "Issues with my form"
},
{
"tags": [
"php",
"arrays"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22076141/timeline",
"question_comments_url": "/questions/22076141/comments",
"question_answers_url": "/questions/22076141/answers",
"question_id": 22076141,
"owner": {
"user_id": 1479092,
"user_type": "registered",
"display_name": "Waldermort",
"reputation": 470,
"email_hash": "a00b970322ae60986ca4ed7629c7389b"
},
"creation_date": 1393522754,
"last_activity_date": 1393522754,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 12,
"score": 0,
"community_owned": false,
"title": "How to find the first free key in an array"
},
{
"tags": [
"php",
"codeigniter",
"postgresql"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22076140/timeline",
"question_comments_url": "/questions/22076140/comments",
"question_answers_url": "/questions/22076140/answers",
"question_id": 22076140,
"owner": {
"user_id": 3220020,
"user_type": "registered",
"display_name": "Kino",
"reputation": 18,
"email_hash": "839332924b8b9e3fdbc1465690378aa2"
},
"creation_date": 1393522752,
"last_activity_date": 1393522752,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 3,
"score": 0,
"community_owned": false,
"title": "multiply 2 values from different table using codeigniter and postgresql foreach()"
},
{
"tags": [
"php"
],
"answer_count": 1,
"favorite_count": 0,
"question_timeline_url": "/questions/22076037/timeline",
"question_comments_url": "/questions/22076037/comments",
"question_answers_url": "/questions/22076037/answers",
"question_id": 22076037,
"owner": {
"user_id": 2719411,
"user_type": "registered",
"display_name": "Xander",
"reputation": 12,
"email_hash": "66a15843818fbcbc6aa01c19ec62aed0"
},
"creation_date": 1393522498,
"last_activity_date": 1393522735,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 24,
"score": 0,
"community_owned": false,
"title": "Hide div based on time - PHP"
},
{
"tags": [
"php",
".htaccess",
"ping",
"password-protection"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22076119/timeline",
"question_comments_url": "/questions/22076119/comments",
"question_answers_url": "/questions/22076119/answers",
"question_id": 22076119,
"owner": {
"user_id": 3361650,
"user_type": "registered",
"display_name": "user3361650",
"reputation": 1,
"email_hash": "84fd66f3c92515f9d2a45a2ca507a0ab"
},
"creation_date": 1393522695,
"last_activity_date": 1393522695,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 8,
"score": 0,
"community_owned": false,
"title": "How to check website is online if it is password protected"
},
{
"tags": [
"php",
"string",
"random"
],
"answer_count": 2,
"favorite_count": 0,
"question_timeline_url": "/questions/22075958/timeline",
"question_comments_url": "/questions/22075958/comments",
"question_answers_url": "/questions/22075958/answers",
"question_id": 22075958,
"owner": {
"user_id": 1573630,
"user_type": "registered",
"display_name": "Michal S",
"reputation": 157,
"email_hash": "05e9ad26aa0851931b7cca5f130ac081"
},
"creation_date": 1393522296,
"last_edit_date": 1393522474,
"last_activity_date": 1393522685,
"up_vote_count": 1,
"down_vote_count": 0,
"view_count": 24,
"score": 1,
"community_owned": false,
"title": "PHP - How to select random tag in the string"
},
{
"tags": [
"php",
"symfony2",
"symfony-forms"
],
"answer_count": 1,
"accepted_answer_id": 22076109,
"favorite_count": 0,
"question_timeline_url": "/questions/22075054/timeline",
"question_comments_url": "/questions/22075054/comments",
"question_answers_url": "/questions/22075054/answers",
"question_id": 22075054,
"owner": {
"user_id": 245552,
"user_type": "registered",
"display_name": "Matthieu Napoli",
"reputation": 7586,
"email_hash": "48906ce482893497d2d7e017cd2f4352"
},
"creation_date": 1393519990,
"last_activity_date": 1393522680,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 9,
"score": 0,
"community_owned": false,
"title": "Symfony form: customize the setter that is called"
},
{
"tags": [
"php",
"wordpress",
"sorting"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22076089/timeline",
"question_comments_url": "/questions/22076089/comments",
"question_answers_url": "/questions/22076089/answers",
"question_id": 22076089,
"owner": {
"user_id": 2279387,
"user_type": "registered",
"display_name": "Tomas Kleinotas",
"reputation": 7,
"email_hash": "6ba9fc650c619efae62691c8456ca76f"
},
"creation_date": 1393522645,
"last_activity_date": 1393522645,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 3,
"score": 0,
"community_owned": false,
"title": "How to sort category posts by meta_value if there are empty fields?"
},
{
"tags": [
"php",
"mysql",
"pdf",
"embed",
"blob"
],
"answer_count": 1,
"favorite_count": 0,
"question_timeline_url": "/questions/22075847/timeline",
"question_comments_url": "/questions/22075847/comments",
"question_answers_url": "/questions/22075847/answers",
"question_id": 22075847,
"owner": {
"user_id": 3346480,
"user_type": "registered",
"display_name": "Richard",
"reputation": 1,
"email_hash": "40e5ef3a529b8b66ec994c2b6a1d1555"
},
"creation_date": 1393522007,
"last_activity_date": 1393522615,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 3,
"score": 0,
"community_owned": false,
"title": "embed pdf from blob to html/php page"
},
{
"tags": [
"php"
],
"answer_count": 2,
"favorite_count": 0,
"question_timeline_url": "/questions/22075599/timeline",
"question_comments_url": "/questions/22075599/comments",
"question_answers_url": "/questions/22075599/answers",
"question_id": 22075599,
"owner": {
"user_id": 3361419,
"user_type": "registered",
"display_name": "Eduardo",
"reputation": 1,
"email_hash": "e3561abf3d1b9969686df7113a4d82f6"
},
"creation_date": 1393521373,
"last_activity_date": 1393522615,
"up_vote_count": 0,
"down_vote_count": 6,
"view_count": 16,
"score": -6,
"community_owned": false,
"title": "Parse syntax error, unexpected end of file in C:\\xampp\\htdocs\\Pap\\create.php on line 292"
},
{
"tags": [
"php",
"forms",
"checkbox",
"tcpdf"
{
"tags": [
"php",
"composer-php",
"directory-structure",
"laravel-4.1"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075957/timeline",
"question_comments_url": "/questions/22075957/comments",
"question_answers_url": "/questions/22075957/answers",
"question_id": 22075957,
"owner": {
"user_id": 1202367,
"user_type": "registered",
"display_name": "Claudio Ludovico Panetta",
"reputation": 393,
"email_hash": "2dca89fe809118d3a93d5a51e2cd28bd"
},
"creation_date": 1393522295,
"last_activity_date": 1393522295,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 5,
"score": 0,
"community_owned": false,
"title": "Centralize vendor folder in Laravel 4.1.x"
},
{
"tags": [
"php",
"sms"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075948/timeline",
"question_comments_url": "/questions/22075948/comments",
"question_answers_url": "/questions/22075948/answers",
"question_id": 22075948,
"owner": {
"user_id": 3333903,
"user_type": "registered",
"display_name": "ArpanTechBuddy",
"reputation": 1,
"email_hash": "2abb3673c9cca94de81942f3b0b0488b"
},
"creation_date": 1393522276,
"last_activity_date": 1393522276,
"up_vote_count": 0,
"down_vote_count": 3,
"view_count": 12,
"score": -3,
"community_owned": false,
"title": "SMS from PHP to any number for free"
},
{
"tags": [
"php",
"curl"
],
"answer_count": 4,
"favorite_count": 0,
"question_timeline_url": "/questions/22075803/timeline",
"question_comments_url": "/questions/22075803/comments",
"question_answers_url": "/questions/22075803/answers",
"question_id": 22075803,
"owner": {
"user_id": 1459253,
"user_type": "registered",
"display_name": "Siddesh Bhalke",
"reputation": 671,
"email_hash": "262597fd50cb34b6ddbc168b8f2d77a5"
},
"creation_date": 1393521922,
"last_activity_date": 1393522259,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 9,
"score": 0,
"community_owned": false,
"title": "curl_init() has been disabled for security reasons"
},
{
"tags": [
"php",
"wordpress",
"rewrite"
],
"answer_count": 2,
"favorite_count": 0,
"question_timeline_url": "/questions/18602715/timeline",
"question_comments_url": "/questions/18602715/comments",
"question_answers_url": "/questions/18602715/answers",
"question_id": 18602715,
"owner": {
"user_id": 648938,
"user_type": "registered",
"display_name": "Scrooby",
"reputation": 2164,
"email_hash": "f280a3e68d054f94c2afa52c950a40b9"
},
"creation_date": 1378248631,
"last_edit_date": 1393521961,
"last_activity_date": 1393522236,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 116,
"score": 0,
"community_owned": false,
"title": "Page Not Found in title of WordPress page on template_redirect using include()"
},
{
"tags": [
"php",
"mysql",
"database-design"
],
"answer_count": 1,
"favorite_count": 0,
"question_timeline_url": "/questions/22075748/timeline",
"question_comments_url": "/questions/22075748/comments",
"question_answers_url": "/questions/22075748/answers",
"question_id": 22075748,
"owner": {
"user_id": 741156,
"user_type": "registered",
"display_name": "Momen M El Zalabany",
"reputation": 957,
"email_hash": "6819dd0de162410dcccd7b1b03bb5def"
},
"creation_date": 1393521798,
"last_edit_date": 1393522196,
"last_activity_date": 1393522196,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 14,
"score": 0,
"community_owned": false,
"title": "mysql design for employees working hours"
},
{
"tags": [
"php",
"logging",
"controller",
"event-handling",
"zend-framework2"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075903/timeline",
"question_comments_url": "/questions/22075903/comments",
"question_answers_url": "/questions/22075903/answers",
"question_id": 22075903,
"owner": {
"user_id": 928044,
"user_type": "registered",
"display_name": "Vincent Caggiari",
"reputation": 8,
"email_hash": "3779e0b7d9bebe76c674bd59fa7016e9"
},
"creation_date": 1393522170,
"last_activity_date": 1393522170,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 4,
"score": 0,
"community_owned": false,
"title": "zend 2 event manager wildcard + keywords"
},
{
"tags": [
"php",
"wordpress"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075764/timeline",
"question_comments_url": "/questions/22075764/comments",
"question_answers_url": "/questions/22075764/answers",
"question_id": 22075764,
"owner": {
"user_id": 1469270,
"user_type": "registered",
"display_name": "tmyie",
"reputation": 515,
"email_hash": "c7522e105f49699af313a6aba52a66bc"
},
"creation_date": 1393521834,
"last_edit_date": 1393522153,
"last_activity_date": 1393522153,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 17,
"score": 0,
"community_owned": false,
"title": "Loop through all posts, show attachment if there (WordPress)"
},
{
"tags": [
"php",
"api",
"paypal",
"express",
"checkout"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22074086/timeline",
"question_comments_url": "/questions/22074086/comments",
"question_answers_url": "/questions/22074086/answers",
"question_id": 22074086,
"owner": {
"user_id": 3361211,
"user_type": "registered",
"display_name": "PmLvgn",
"reputation": 1,
"email_hash": "a4df4e1cb22b77c2e898d791c117a3a5"
},
"creation_date": 1393517599,
"last_edit_date": 1393522102,
"last_activity_date": 1393522102,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 8,
"score": 0,
"community_owned": false,
"title": "PHP Paypal API ExpressCheckout, i don't know what i sold in history details"
},
{
"tags": [
"php",
"braintree"
],
"answer_count": 1,
"favorite_count": 0,
"question_timeline_url": "/questions/22056863/timeline",
"question_comments_url": "/questions/22056863/comments",
"question_answers_url": "/questions/22056863/answers",
"question_id": 22056863,
"owner": {
"user_id": 1233455,
"user_type": "registered",
"display_name": "JasonMortonNZ",
"reputation": 967,
"email_hash": "1d2bc25a4d7db82dd86c411afda88e8f"
},
"creation_date": 1393462513,
"last_activity_date": 1393522017,
"up_vote_count": 1,
"down_vote_count": 0,
"view_count": 12,
"score": 1,
"community_owned": false,
"title": "Braintree API in PHP success and currency issue"
},
{
"tags": [
"php"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075831/timeline",
"question_comments_url": "/questions/22075831/comments",
"question_answers_url": "/questions/22075831/answers",
"question_id": 22075831,
"owner": {
"user_id": 3282713,
"user_type": "registered",
"display_name": "user3282713",
"reputation": 1,
"email_hash": "0fdeb1c7e8da488a6556ccc8386d0249"
},
"creation_date": 1393521988,
"last_activity_date": 1393521988,
"up_vote_count": 0,
"down_vote_count": 0,
"view_count": 6,
"score": 0,
"community_owned": false,
"title": "updating multiple items through checkbox in php"
},
{
"tags": [
"php",
"html"
],
"answer_count": 0,
"favorite_count": 0,
"question_timeline_url": "/questions/22075634/timeline",
"question_comments_url": "/questions/22075634/comments",
"question_answers_url": "/questions/22075634/answers",
"question_id": 22075634,
"owner": {
"user_id": 2640557,
"user_type": "registered",
"display_name": "aveleon",
"reputation": 20,
"email_hash": "b20903bea6646401a4d88a7852ae6229"
},
"creation_date": 1393521474,
"last_edit_date": 1393521949,
"last_activity_date": 1393521949,
"up_vote_count": 1,
"down_vote_count": 1,
"view_count": 44,
"score": 0,
"community_owned": false,
"title": "PHP is not working and cannot find out why (creating dynamic content)"
},
{
"tags": [
"php",
"android",
"web-services",
"mobile",
"service"
],
"answer_count": 1,
"favorite_count": 1,
"closed_date": 1393520310,
"closed_reason": "primarily opinion-based",
"question_timeline_url": "/questions/22075094/timeline",
"question_comments_url": "/questions/22075094/comments",
"question_answers_url": "/questions/22075094/answers",
"question_id": 22075094,
"owner": {
"user_id": 2715065,
"user_type": "registered",
"display_name": "Warde",
"reputation": 285,
"email_hash": "f265910523dec1dc1e11bb02b4af79a5"
},
"creation_date": 1393520062,
"last_edit_date": 1393521803,
"last_activity_date": 1393521803,
"up_vote_count": 0,
"down_vote_count": 9,
"view_count": 35,
"score": -9,
"community_owned": false,
"title": "Need a service that sends the complete information of contacts to the server"
}
]
}
Getting below error when i try json_decode('abovedata'),
ERROR:
Catchable fatal error: Object of class stdClass could not be
converted to string in F:\xamp\htdocs\xampp\curl.php on line 12
How can i read each key values from above json data ?
Try this..
json_decode($data,true);
Your JSON is invalid, that is why the function is not processing it correctly.
"tags": [
"php",
"forms",
"checkbox",
"tcpdf"
Look at this section here, you never close the [] in "tags". I used this JSON validator

Categories