I am trying to get the order list using the below url,
GET METHOD - http://magento.local/index.php/rest/V1/orders?searchCriteria
Header: Authorization: Bearer TOKEN(Customer Token)
But its giving the following response,
{
"message": "Consumer is not authorized to access %resources",
"parameters": {
"resources": "Magento_Sales::sales"
}
}
what needs to be done to get the order list using customer token?
Unfortunately it's not implemented in Magento_Sales::sales yet, but you can extend your own API. follow the following issue:
https://github.com/magento/magento2/issues/3552
For the get Customer Order history use searchCriteria and passed customer_email id.
Follow below Magento 2 API to get the customer order history.
Request URL:
https://magento.com/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=customer_email&searchCriteria[filter_groups][0][filters][0][value]=test#gmail.com
Method: GET
Response:
{
"items": [
{
"base_currency_code": "KWD",
"base_discount_amount": 0,
"base_grand_total": 40,
"base_discount_tax_compensation_amount": 0,
"base_shipping_amount": 10,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 10,
"base_shipping_tax_amount": 0,
"base_subtotal": 30,
"base_subtotal_incl_tax": 30,
"base_tax_amount": 0,
"base_total_due": 40,
"base_to_global_rate": 1,
"base_to_order_rate": 1,
"billing_address_id": 250,
"created_at": "2019-08-14 11:26:48",
"customer_email": "test#gmail.com",
"customer_firstname": "Test",
"customer_group_id": 1,
"customer_id": 51,
"customer_is_guest": 0,
"customer_lastname": "Customer",
"customer_note_notify": 1,
"discount_amount": 0,
"email_sent": 1,
"entity_id": 125,
"global_currency_code": "KWD",
"grand_total": 40,
"discount_tax_compensation_amount": 0,
"increment_id": "000000119",
"is_virtual": 0,
"order_currency_code": "KWD",
"protect_code": "9a7b171724410d42aec193ba5206901e",
"quote_id": 398,
"remote_ip": "202.131.115.180",
"shipping_amount": 10,
"shipping_description": "Flat Rate - Fixed",
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 10,
"shipping_tax_amount": 0,
"state": "new",
"status": "pending",
"store_currency_code": "KWD",
"store_id": 1,
"store_name": "Default Store",
"store_to_base_rate": 0,
"store_to_order_rate": 0,
"subtotal": 30,
"subtotal_incl_tax": 30,
"tax_amount": 0,
"total_due": 40,
"total_item_count": 1,
"total_qty_ordered": 2,
"updated_at": "2019-08-14 11:26:49",
"weight": 0,
"items": [
{
"amount_refunded": 0,
"base_amount_refunded": 0,
"base_cost": 8.5,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_original_price": 15,
"base_price": 15,
"base_price_incl_tax": 15,
"base_row_invoiced": 0,
"base_row_total": 30,
"base_row_total_incl_tax": 30,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2019-08-14 11:26:48",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 341,
"name": "DIAMOND GLITTER GRAY",
"no_discount": 0,
"order_id": 125,
"original_price": 15,
"price": 15,
"price_incl_tax": 15,
"product_id": 228,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 0,
"qty_ordered": 2,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 1281,
"row_invoiced": 0,
"row_total": 30,
"row_total_incl_tax": 30,
"row_weight": 0,
"sku": "CLBELGLG0175DCMO",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2019-08-14 11:26:48"
}
],
"billing_address": {
"address_type": "billing",
"city": "California",
"company": "Company",
"country_id": "US",
"email": "test#gmail.com",
"entity_id": 250,
"firstname": "john",
"lastname": "harrison",
"parent_id": 125,
"postcode": "12345",
"region": "New York",
"region_code": "NY",
"region_id": 43,
"street": [
"Street Address"
],
"telephone": "2313131312"
},
"payment": {
"account_status": null,
"additional_information": [
"Check / Money order"
],
"amount_ordered": 40,
"base_amount_ordered": 40,
"base_shipping_amount": 10,
"cc_exp_year": "0",
"cc_last4": null,
"cc_ss_start_month": "0",
"cc_ss_start_year": "0",
"entity_id": 125,
"method": "checkmo",
"parent_id": 125,
"shipping_amount": 10
},
"status_histories": [],
"extension_attributes": {
"shipping_assignments": [
{
"shipping": {
"address": {
"address_type": "shipping",
"city": "California",
"company": "Company",
"country_id": "US",
"email": "test#gmail.com",
"entity_id": 249,
"firstname": "john",
"lastname": "harrison",
"parent_id": 125,
"postcode": "12345",
"region": "New York",
"region_code": "NY",
"region_id": 43,
"street": [
"Street Address"
],
"telephone": "2313131312"
},
"method": "flatrate_flatrate",
"total": {
"base_shipping_amount": 10,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 10,
"base_shipping_tax_amount": 0,
"shipping_amount": 10,
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 10,
"shipping_tax_amount": 0
}
},
"items": [
{
"amount_refunded": 0,
"base_amount_refunded": 0,
"base_cost": 8.5,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_original_price": 15,
"base_price": 15,
"base_price_incl_tax": 15,
"base_row_invoiced": 0,
"base_row_total": 30,
"base_row_total_incl_tax": 30,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2019-08-14 11:26:48",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 341,
"name": "BELLA DIAMOND GLITTER GRAY 0175",
"no_discount": 0,
"order_id": 125,
"original_price": 15,
"price": 15,
"price_incl_tax": 15,
"product_id": 228,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 0,
"qty_ordered": 2,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 1281,
"row_invoiced": 0,
"row_total": 30,
"row_total_incl_tax": 30,
"row_weight": 0,
"sku": "CLBELGLG0175DCMO",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2019-08-14 11:26:48"
}
]
}
],
"rewards_discount": 0,
"rewards_spend": 0,
"rewards_earn": 950
}
},
{
"applied_rule_ids": "4,11",
"base_currency_code": "KWD",
"base_discount_amount": -15,
"base_grand_total": 165,
"base_discount_tax_compensation_amount": 0,
"base_shipping_amount": 45,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 45,
"base_shipping_tax_amount": 0,
"base_subtotal": 135,
"base_subtotal_incl_tax": 135,
"base_tax_amount": 0,
"base_total_due": 165,
"base_to_global_rate": 1,
"base_to_order_rate": 1,
"billing_address_id": 268,
"created_at": "2019-09-24 13:16:32",
"customer_email": "test#gmail.com",
"customer_firstname": "Test",
"customer_group_id": 1,
"customer_id": 51,
"customer_is_guest": 0,
"customer_lastname": "Customer",
"customer_note_notify": 1,
"discount_amount": -15,
"email_sent": 1,
"entity_id": 134,
"global_currency_code": "KWD",
"grand_total": 165,
"discount_tax_compensation_amount": 0,
"increment_id": "000000128",
"is_virtual": 0,
"order_currency_code": "KWD",
"protect_code": "1deccd785628b2df682d9156db732fc0",
"quote_id": 408,
"shipping_amount": 45,
"shipping_description": "Flat Rate - Fixed",
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 45,
"shipping_tax_amount": 0,
"state": "new",
"status": "pending",
"store_currency_code": "KWD",
"store_id": 1,
"store_name": "Default Store",
"store_to_base_rate": 0,
"store_to_order_rate": 0,
"subtotal": 135,
"subtotal_incl_tax": 135,
"tax_amount": 0,
"total_due": 165,
"total_item_count": 1,
"total_qty_ordered": 9,
"updated_at": "2019-09-24 13:16:33",
"weight": 0,
"items": [
{
"amount_refunded": 0,
"applied_rule_ids": "4,11",
"base_amount_refunded": 0,
"base_cost": 8.5,
"base_discount_amount": 15,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_original_price": 15,
"base_price": 15,
"base_price_incl_tax": 15,
"base_row_invoiced": 0,
"base_row_total": 135,
"base_row_total_incl_tax": 135,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2019-09-24 13:16:32",
"discount_amount": 15,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 351,
"name": "BELLA DIAMOND GLITTER GRAY 0175",
"no_discount": 0,
"order_id": 134,
"original_price": 15,
"price": 15,
"price_incl_tax": 15,
"product_id": 228,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 0,
"qty_ordered": 9,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 1378,
"row_invoiced": 0,
"row_total": 135,
"row_total_incl_tax": 135,
"row_weight": 0,
"sku": "CLBELGLG0175DCMO",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2019-09-24 13:16:32"
}
],
"billing_address": {
"address_type": "billing",
"city": "California",
"company": "Company",
"country_id": "US",
"email": "test#gmail.com",
"entity_id": 268,
"firstname": "john",
"lastname": "harrison",
"parent_id": 134,
"postcode": "12345",
"region": "New York",
"region_code": "NY",
"region_id": 43,
"street": [
"Street Address"
],
"telephone": "2313131312"
},
"payment": {
"account_status": null,
"additional_information": [
"Check / Money order"
],
"amount_ordered": 165,
"base_amount_ordered": 165,
"base_shipping_amount": 45,
"cc_exp_year": "0",
"cc_last4": null,
"cc_ss_start_month": "0",
"cc_ss_start_year": "0",
"entity_id": 134,
"method": "checkmo",
"parent_id": 134,
"shipping_amount": 45
},
"status_histories": [],
"extension_attributes": {
"shipping_assignments": [
{
"shipping": {
"address": {
"address_type": "shipping",
"city": "California",
"company": "Company",
"country_id": "US",
"email": "test#gmail.com",
"entity_id": 267,
"firstname": "john",
"lastname": "harrison",
"parent_id": 134,
"postcode": "12345",
"region": "New York",
"region_code": "NY",
"region_id": 43,
"street": [
"Street Address"
],
"telephone": "2313131312"
},
"method": "flatrate_flatrate",
"total": {
"base_shipping_amount": 45,
"base_shipping_discount_amount": 0,
"base_shipping_discount_tax_compensation_amnt": 0,
"base_shipping_incl_tax": 45,
"base_shipping_tax_amount": 0,
"shipping_amount": 45,
"shipping_discount_amount": 0,
"shipping_discount_tax_compensation_amount": 0,
"shipping_incl_tax": 45,
"shipping_tax_amount": 0
}
},
"items": [
{
"amount_refunded": 0,
"applied_rule_ids": "4,11",
"base_amount_refunded": 0,
"base_cost": 8.5,
"base_discount_amount": 15,
"base_discount_invoiced": 0,
"base_discount_tax_compensation_amount": 0,
"base_original_price": 15,
"base_price": 15,
"base_price_incl_tax": 15,
"base_row_invoiced": 0,
"base_row_total": 135,
"base_row_total_incl_tax": 135,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2019-09-24 13:16:32",
"discount_amount": 15,
"discount_invoiced": 0,
"discount_percent": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 351,
"name": "BELLA DIAMOND GLITTER GRAY 0175",
"no_discount": 0,
"order_id": 134,
"original_price": 15,
"price": 15,
"price_incl_tax": 15,
"product_id": 228,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 0,
"qty_ordered": 9,
"qty_refunded": 0,
"qty_shipped": 0,
"quote_item_id": 1378,
"row_invoiced": 0,
"row_total": 135,
"row_total_incl_tax": 135,
"row_weight": 0,
"sku": "CLBELGLG0175DCMO",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2019-09-24 13:16:32"
}
]
}
],
"rewards_discount": 0,
"rewards_spend": 0,
"rewards_earn": 3770
}
}
],
"search_criteria": {
"filter_groups": [
{
"filters": [
{
"field": "customer_email",
"value": "test#gmail.com",
"condition_type": "eq"
}
]
}
]
},
"total_count": 2
}
Related
I need to loop through and print all nested data within the "players" array and sort by "wonAmount." I can get my PHP to print out a single value, which I target, but I can't get it to work when I try the foreach loop. So instead, it prints out "array."
JSON
{
"tournamentID": 65,
"gameType": "Holdem",
"name": "TRI KRALJA ZA EVROPU",
"start": "2022-04-07 13:30:00",
"status": "Finished",
"buyIn": 100000,
"entryFee": 10000,
"guaranteedPrize": 12500000,
"rebuyFee": 100000,
"rebuyRake": 10000,
"addonFee": 0,
"addonRake": 0,
"tableSize": 9,
"speed": "Turbo",
"players": [
{
"id": 1000000,
"alias": "demo1",
"rank": 1,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 6250000
},
{
"id": 1000005,
"alias": "demo6",
"rank": 2,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 3750000
},
{
"id": 1000087,
"alias": "demo10",
"rank": 3,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 2500000
},
{
"id": 1000008,
"alias": "demo9",
"rank": 4,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000078,
"alias": "demo15",
"rank": 5,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000002,
"alias": "demo3",
"rank": 6,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000006,
"alias": "demo7",
"rank": 7,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000090,
"alias": "demo13",
"rank": 8,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000171,
"alias": "demo14",
"rank": 9,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000088,
"alias": "okokoke",
"rank": 10,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000007,
"alias": "demo8",
"rank": 11,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000086,
"alias": "demo11",
"rank": 12,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000004,
"alias": "demo5",
"rank": 13,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000001,
"alias": "demo2",
"rank": 14,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000003,
"alias": "demo4",
"rank": 15,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
},
{
"id": 1000077,
"alias": "helloworld",
"rank": 16,
"rebuyCount": 0,
"addonCount": 0,
"wonAmount": 0
}
]
}
first, you need to decode the json using json_decode then you need to sort & print the player's array
$data = json_decode($json_data,true);
//extract the players from json
$players = $data["players"];
//sort players array
$wonAmount = array();
foreach ($players as $key => $row)
{
$wonAmount[$key] = $row['wonAmount'];
}
array_multisort($wonAmount, SORT_DESC, $players);
//print players data
foreach ($players as $player)
{
//add here any keys you want to print from player array
echo $player["id"];
}
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 1 year ago.
This is my json in postman:
[
[
{
"amount_refunded": 1,
"base_amount_refunded": 1,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_refunded": 0,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_discount_tax_compensation_refunded": 0,
"base_original_price": 1,
"base_price": 1,
"base_price_incl_tax": 1,
"base_row_invoiced": 1,
"base_row_total": 1,
"base_row_total_incl_tax": 1,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"base_tax_refunded": 0,
"created_at": "2021-10-04 13:02:36",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"discount_refunded": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"discount_tax_compensation_refunded": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 166,
"name": "Configurable Product 16 - option 21",
"no_discount": 0,
"order_id": 85,
"original_price": 1,
"price": 1,
"price_incl_tax": 1,
"product_id": 1234,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 1,
"qty_ordered": 1,
"qty_refunded": 1,
"qty_shipped": 1,
"quote_item_id": 164,
"row_invoiced": 1,
"row_total": 1,
"row_total_incl_tax": 1,
"row_weight": 1,
"sku": "Configurable Product 16 - option 21",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"tax_refunded": 0,
"updated_at": "2021-10-15 09:28:44",
"weee_tax_applied": "[]",
"weight": 1
}
],
[
{
"amount_refunded": 80,
"applied_rule_ids": "1",
"base_amount_refunded": 80,
"base_discount_amount": 8,
"base_discount_invoiced": 8,
"base_discount_refunded": 8,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_discount_tax_compensation_refunded": 0,
"base_original_price": 80,
"base_price": 80,
"base_price_incl_tax": 86.6,
"base_row_invoiced": 80,
"base_row_total": 72,
"base_row_total_incl_tax": 77.94,
"base_tax_amount": 5.94,
"base_tax_invoiced": 5.94,
"base_tax_refunded": 5.94,
"created_at": "2021-10-15 11:23:54",
"discount_amount": 8,
"discount_invoiced": 8,
"discount_percent": 10,
"discount_refunded": 8,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"discount_tax_compensation_refunded": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 169,
"name": "Ski vest 92",
"no_discount": 0,
"order_id": 88,
"original_price": 80,
"price": 80,
"price_incl_tax": 86.6,
"product_id": 1267,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 1,
"qty_ordered": 1,
"qty_refunded": 1,
"qty_shipped": 1,
"quote_item_id": 171,
"row_invoiced": 80,
"row_total": 72,
"row_total_incl_tax": 77.94,
"row_weight": 5,
"sku": "Ski vest 92",
"store_id": 1,
"tax_amount": 5.94,
"tax_invoiced": 5.94,
"tax_percent": 8.25,
"tax_refunded": 5.94,
"updated_at": "2021-10-15 11:25:07",
"weee_tax_applied": "[]",
"weight": 5
},
{
"amount_refunded": 0,
"applied_rule_ids": "1",
"base_amount_refunded": 0,
"base_discount_amount": 2,
"base_discount_invoiced": 2,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_original_price": 20,
"base_price": 20,
"base_price_incl_tax": 20,
"base_row_invoiced": 20,
"base_row_total": 18,
"base_row_total_incl_tax": 18,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"created_at": "2021-10-15 11:23:54",
"discount_amount": 2,
"discount_invoiced": 2,
"discount_percent": 10,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 170,
"name": "testcron",
"no_discount": 0,
"order_id": 88,
"original_price": 20,
"price": 20,
"price_incl_tax": 20,
"product_id": 1260,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 1,
"qty_ordered": 1,
"qty_refunded": 0,
"qty_shipped": 1,
"quote_item_id": 173,
"row_invoiced": 20,
"row_total": 18,
"row_total_incl_tax": 18,
"row_weight": 2,
"sku": "testcron",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"updated_at": "2021-10-15 11:24:39",
"weee_tax_applied": "[]",
"weight": 2
},
{
"amount_refunded": 0,
"applied_rule_ids": "1",
"base_amount_refunded": 0,
"base_discount_amount": 0.5,
"base_discount_invoiced": 0.5,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_original_price": 5,
"base_price": 5,
"base_price_incl_tax": 5.41,
"base_row_invoiced": 5,
"base_row_total": 4.5,
"base_row_total_incl_tax": 4.87,
"base_tax_amount": 0.37,
"base_tax_invoiced": 0.37,
"created_at": "2021-10-15 11:23:54",
"discount_amount": 0.5,
"discount_invoiced": 0.5,
"discount_percent": 10,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 171,
"name": "time",
"no_discount": 0,
"order_id": 88,
"original_price": 5,
"price": 5,
"price_incl_tax": 5.41,
"product_id": 1261,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 1,
"qty_ordered": 1,
"qty_refunded": 0,
"qty_shipped": 1,
"quote_item_id": 174,
"row_invoiced": 5,
"row_total": 4.5,
"row_total_incl_tax": 4.87,
"row_weight": 2,
"sku": "time",
"store_id": 1,
"tax_amount": 0.37,
"tax_invoiced": 0.37,
"tax_percent": 8.25,
"updated_at": "2021-10-15 11:24:39",
"weee_tax_applied": "[]",
"weight": 2
}
],
[
{
"amount_refunded": 80,
"base_amount_refunded": 80,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_refunded": 0,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_discount_tax_compensation_refunded": 0,
"base_original_price": 80,
"base_price": 80,
"base_price_incl_tax": 80,
"base_row_invoiced": 80,
"base_row_total": 80,
"base_row_total_incl_tax": 80,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"base_tax_refunded": 0,
"created_at": "2021-10-19 08:49:35",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"discount_refunded": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"discount_tax_compensation_refunded": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 172,
"name": "Ski vest 92",
"no_discount": 0,
"order_id": 89,
"original_price": 80,
"price": 80,
"price_incl_tax": 80,
"product_id": 1267,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 1,
"qty_ordered": 1,
"qty_refunded": 1,
"qty_shipped": 1,
"quote_item_id": 175,
"row_invoiced": 80,
"row_total": 80,
"row_total_incl_tax": 80,
"row_weight": 5,
"sku": "Ski vest 92",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"tax_refunded": 0,
"updated_at": "2021-10-19 09:06:19",
"weee_tax_applied": "[]",
"weight": 5
},
{
"amount_refunded": 5,
"base_amount_refunded": 5,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_refunded": 0,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_discount_tax_compensation_refunded": 0,
"base_original_price": 5,
"base_price": 5,
"base_price_incl_tax": 5,
"base_row_invoiced": 5,
"base_row_total": 5,
"base_row_total_incl_tax": 5,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"base_tax_refunded": 0,
"created_at": "2021-10-19 08:49:35",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"discount_refunded": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"discount_tax_compensation_refunded": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 173,
"name": "time",
"no_discount": 0,
"order_id": 89,
"original_price": 5,
"price": 5,
"price_incl_tax": 5,
"product_id": 1261,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 1,
"qty_ordered": 1,
"qty_refunded": 1,
"qty_shipped": 1,
"quote_item_id": 177,
"row_invoiced": 5,
"row_total": 5,
"row_total_incl_tax": 5,
"row_weight": 2,
"sku": "time",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"tax_refunded": 0,
"updated_at": "2021-10-19 09:06:19",
"weee_tax_applied": "[]",
"weight": 2
}
],
[
{
"amount_refunded": 5,
"base_amount_refunded": 5,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_refunded": 0,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_discount_tax_compensation_refunded": 0,
"base_original_price": 5,
"base_price": 5,
"base_price_incl_tax": 5.41,
"base_row_invoiced": 5,
"base_row_total": 5,
"base_row_total_incl_tax": 5.41,
"base_tax_amount": 0.41,
"base_tax_invoiced": 0.41,
"base_tax_refunded": 0.41,
"created_at": "2021-10-19 10:27:53",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"discount_refunded": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"discount_tax_compensation_refunded": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 176,
"name": "Configurable Product 16",
"no_discount": 0,
"order_id": 91,
"original_price": 5,
"price": 5,
"price_incl_tax": 5.41,
"product_id": 1253,
"product_type": "configurable",
"qty_canceled": 0,
"qty_invoiced": 1,
"qty_ordered": 1,
"qty_refunded": 1,
"qty_shipped": 1,
"quote_item_id": 180,
"row_invoiced": 5,
"row_total": 5,
"row_total_incl_tax": 5.41,
"row_weight": 1,
"sku": "Configurable Product 16 - option 9",
"store_id": 1,
"tax_amount": 0.41,
"tax_invoiced": 0.41,
"tax_percent": 8.25,
"tax_refunded": 0.41,
"updated_at": "2021-10-19 10:50:02",
"weee_tax_applied": "[]",
"weight": 1,
"product_option": {
"extension_attributes": {
"configurable_item_options": [
{
"option_id": "212",
"option_value": 478
},
{
"option_id": "213",
"option_value": 480
}
]
}
}
},
{
"amount_refunded": 0,
"base_amount_refunded": 0,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_refunded": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_discount_tax_compensation_refunded": 0,
"base_price": 0,
"base_row_invoiced": 0,
"base_row_total": 0,
"base_tax_amount": 0,
"base_tax_invoiced": 0,
"base_tax_refunded": 0,
"created_at": "2021-10-19 10:27:53",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"discount_refunded": 0,
"free_shipping": 0,
"discount_tax_compensation_invoiced": 0,
"discount_tax_compensation_refunded": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 177,
"name": "Configurable Product 16 - option 9",
"no_discount": 0,
"order_id": 91,
"original_price": 0,
"parent_item_id": 176,
"price": 0,
"product_id": 1222,
"product_type": "simple",
"qty_canceled": 0,
"qty_invoiced": 1,
"qty_ordered": 1,
"qty_refunded": 1,
"qty_shipped": 0,
"quote_item_id": 181,
"row_invoiced": 0,
"row_total": 0,
"row_weight": 0,
"sku": "Configurable Product 16 - option 9",
"store_id": 1,
"tax_amount": 0,
"tax_invoiced": 0,
"tax_percent": 0,
"tax_refunded": 0,
"updated_at": "2021-10-19 10:50:02",
"weight": 1,
"parent_item": {
"amount_refunded": 5,
"base_amount_refunded": 5,
"base_discount_amount": 0,
"base_discount_invoiced": 0,
"base_discount_refunded": 0,
"base_discount_tax_compensation_amount": 0,
"base_discount_tax_compensation_invoiced": 0,
"base_discount_tax_compensation_refunded": 0,
"base_original_price": 5,
"base_price": 5,
"base_price_incl_tax": 5.41,
"base_row_invoiced": 5,
"base_row_total": 5,
"base_row_total_incl_tax": 5.41,
"base_tax_amount": 0.41,
"base_tax_invoiced": 0.41,
"base_tax_refunded": 0.41,
"created_at": "2021-10-19 10:27:53",
"discount_amount": 0,
"discount_invoiced": 0,
"discount_percent": 0,
"discount_refunded": 0,
"free_shipping": 0,
"discount_tax_compensation_amount": 0,
"discount_tax_compensation_invoiced": 0,
"discount_tax_compensation_refunded": 0,
"is_qty_decimal": 0,
"is_virtual": 0,
"item_id": 176,
"name": "Configurable Product 16",
"no_discount": 0,
"order_id": 91,
"original_price": 5,
"price": 5,
"price_incl_tax": 5.41,
"product_id": 1253,
"product_type": "configurable",
"qty_canceled": 0,
"qty_invoiced": 1,
"qty_ordered": 1,
"qty_refunded": 1,
"qty_shipped": 1,
"quote_item_id": 180,
"row_invoiced": 5,
"row_total": 5,
"row_total_incl_tax": 5.41,
"row_weight": 1,
"sku": "Configurable Product 16 - option 9",
"store_id": 1,
"tax_amount": 0.41,
"tax_invoiced": 0.41,
"tax_percent": 8.25,
"tax_refunded": 0.41,
"updated_at": "2021-10-19 10:50:02",
"weee_tax_applied": "[]",
"weight": 1,
"product_option": {
"extension_attributes": {
"configurable_item_options": [
{
"option_id": "212",
"option_value": 478
},
{
"option_id": "213",
"option_value": 480
}
]
}
}
},
"row_total_incl_tax": 0,
"base_row_total_incl_tax": 0
}
]
]
I am trying to loop threough this json so I can get all the "amount_refunded values".
This is the code that I have now but I don't understand how I can get the amount_refunded values.
Note that ->items is used and is correct because it needs to get all the items.
public function getRefundedOrders(Request $request)
{
try{
$response = Http::withToken($request->post('token'))
->get($request->post('URL').'/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=base_subtotal_refunded&searchCriteria[filter_groups][0][filters][0][condition_type]=gt');
}
catch(Throwaway $e){
Log::error($e);
}
$refunds = json_decode($response);
$user = Users::whereUrl($request->post('URL'))->firstOrFail();
$refundedItems = [];
foreach($refunds->items as $product){
array_push($refundedItems, $product->items);
}
$refundedProducts = [];
if (isset($response['message']))
{
return response()->json(['type' => 'error', 'message' => $response['message']]);
}
return $refundedItems;
}
I don't understand how I can loop through this so I can get all the amount_refunded from every object inside of this json.
Assuming your json is missing a closing "]", then decode it into an associative array using :
$string = '--yourjsongoeshere--';
$data = json_decode($string, true);
then set your total refunds to 0, loop through the arrays and add the total refunds to it.
$totalrefund = 0;
foreach($data as $datum) {
foreach($datum as $entry) {
$totalrefund += $entry['amount_refunded'];
}
}
echo $totalrefund;
You can use Laravel collection to get an array of amount_refunded.
$refunds = collect(json_decode($response))
->flatten()
->pluck('amount_refunded')
->toArray();
To get all data filtered by amount_refunded > 0
$refunds = collect(json_decode($response))->flatten()->filter(function ($item) {
return $item->amount_refunded > 0;
})->toArray();
Docs: https://laravel.com/docs/8.x/collections#available-methods
Assuming the JSON you've shown is the contents of $response, there is no "items" mentioned anywhere in the JSON, so it's not clear why you included that or why you think it's working. It would definitely cause errors / warnings if you tried to use the code you've shown with that data.
Your JSON structure is an outer array, with multiple smaller arrays inside it - and each of those smaller arrays can have one or more entries.
This simple code will just output the value of each "amount_refunded" field, by looping through the outer array, and then looping through each of the inner ones:
$refunds = json_decode($response);
foreach($refunds as $refund) {
foreach ($refund as $item)
echo $item->amount_refunded.PHP_EOL; //PHP_EOL just adds a newline character. Use <br/> instead for HTML output.
}
Working demo: http://sandbox.onlinephpfunctions.com/code/728b81aa408b811b9d98a0c01d3dc782c4f05951
Laravel custom pagination page 2 result return as object not array.
This is my code of custom pagination
function custom_paginate($data)
{
//Get current page form url e.g. &page=6
$currentPage = LengthAwarePaginator::resolveCurrentPage();
//Create a new Laravel collection from the array data
$collection = new Collection($data);
//Define how many items we want to be visible in each page
$per_page = (int) per_page();
//Slice the collection to get the items to display in current page
$currentPageResults = $collection->slice(($currentPage - 1) * $per_page, $per_page)->all();
//Create our paginator and add it to the data array
$data['results'] = new LengthAwarePaginator($currentPageResults, count($collection), $per_page);
//Set base url for pagination links to follow e.g custom/url?page=6
return $data['results']->setPath(request()->url());
}
when i am at page 1 data is coming as array but in same code if i passed page=2result is coming as object.
Expected result
{
"current_page": 2,
"data": [
{
"_id": 34,
"state": "Andaman & Nicobar Islands",
"post_count": 8,
"totalPhotos": 0,
"totalVideos": 1,
"totalAudios": 0
},
{
"_id": 28,
"state": "Andhra Pradesh",
"post_count": 888,
"totalPhotos": 0,
"totalVideos": 111,
"totalAudios": 0
},
{
"_id": 12,
"state": "Arunachal Pradesh",
"post_count": 200,
"totalPhotos": 0,
"totalVideos": 25,
"totalAudios": 0
},
{
"_id": 18,
"state": "Assam",
"post_count": 464,
"totalPhotos": 0,
"totalVideos": 58,
"totalAudios": 0
},
{
"_id": 10,
"state": "Bihar",
"post_count": 1072,
"totalPhotos": 0,
"totalVideos": 134,
"totalAudios": 0
}
],
"first_page_url": "http://swachh-manch-data.git/insight/posts?page=1",
"from": 6,
"last_page": 8,
"last_page_url": "http://swachh-manch-data.git/insight/posts?page=8",
"next_page_url": "http://swachh-manch-data.git/insight/posts?page=3",
"path": "http://swachh-manch-data.git/insight/posts",
"per_page": 5,
"prev_page_url": "http://swachh-manch-data.git/insight/posts?page=1",
"to": 10,
"total": 36
}
but getting data as object on page 2 (Actual result)
{
"current_page": 2,
"data": {
"5": {
"_id": 4,
"state": "Chandigarh",
"post_count": 8,
"totalPhotos": 0,
"totalVideos": 1,
"totalAudios": 0
},
"6": {
"_id": 22,
"state": "Chhattisgarh",
"post_count": 1336,
"totalPhotos": 0,
"totalVideos": 167,
"totalAudios": 0
},
"7": {
"_id": 26,
"state": "Dadra & Nagar Haveli",
"post_count": 8,
"totalPhotos": 0,
"totalVideos": 1,
"totalAudios": 0
},
"8": {
"_id": 25,
"state": "Daman & Diu",
"post_count": 16,
"totalPhotos": 0,
"totalVideos": 2,
"totalAudios": 0
},
"9": {
"_id": 7,
"state": "Delhi",
"post_count": 40,
"totalPhotos": 0,
"totalVideos": 5,
"totalAudios": 0
}
},
"first_page_url": "http://swachh-manch-data.git/insight/posts?page=1",
"from": 6,
"last_page": 8,
"last_page_url": "http://swachh-manch-data.git/insight/posts?page=8",
"next_page_url": "http://swachh-manch-data.git/insight/posts?page=3",
"path": "http://swachh-manch-data.git/insight/posts",
"per_page": 5,
"prev_page_url": "http://swachh-manch-data.git/insight/posts?page=1",
"to": 10,
"total": 36
}
i am not sure but the problem is in $currentPageResults = $collection->slice(($currentPage - 1) * $per_page, $per_page)->all(); this line.
Thanks in advance. :)
Change
$currentPageResults = $collection->slice(($currentPage - 1) * $per_page, $per_page)->all();
to
$currentPageResults = $collection->slice(($currentPage - 1) * $per_page, $per_page)->values();
for more info read this.
Simply i have queried an api to return some data for a game. The result is an array where each set contains epoch datecreated field.
Using php i want to be able to filter out all the data for only data containing datecreated > 1444639042(epoch time).
How is that possible?
I am using leaguewrap from github as my class to pull data so:
// Get Match History
$game = $api->game();
$games = $game->recent($loluser);
returns:
{
"games": [
{
"fellowPlayers": [
{
"championId": 84,
"teamId": 200,
"summonerId": 4972120
},
{
"championId": 23,
"teamId": 200,
"summonerId": 1011313
},
{
"championId": 18,
"teamId": 100,
"summonerId": 456905
},
{
"championId": 77,
"teamId": 100,
"summonerId": 2751172
},
{
"championId": 131,
"teamId": 100,
"summonerId": 5100445
},
{
"championId": 1,
"teamId": 200,
"summonerId": 841536
},
{
"championId": 99,
"teamId": 200,
"summonerId": 4400359
},
{
"championId": 18,
"teamId": 200,
"summonerId": 3652614
},
{
"championId": 80,
"teamId": 100,
"summonerId": 600691
}
],
"gameType": "MATCHED_GAME",
"stats": {
"totalDamageDealtToChampions": 17713,
"goldEarned": 11117,
"item1": 3174,
"wardPlaced": 15,
"totalDamageTaken": 19563,
"item0": 1056,
"trueDamageDealtPlayer": 4,
"physicalDamageDealtPlayer": 10423,
"trueDamageDealtToChampions": 4,
"killingSprees": 1,
"playerRole": 2,
"totalUnitsHealed": 3,
"playerPosition": 4,
"level": 16,
"magicDamageDealtToChampions": 16682,
"turretsKilled": 2,
"magicDamageDealtPlayer": 81369,
"neutralMinionsKilledEnemyJungle": 3,
"assists": 9,
"magicDamageTaken": 11659,
"numDeaths": 5,
"totalTimeCrowdControlDealt": 326,
"largestMultiKill": 1,
"physicalDamageTaken": 7526,
"sightWardsBought": 2,
"team": 100,
"win": false,
"totalDamageDealt": 91797,
"largestKillingSpree": 5,
"totalHeal": 2398,
"item4": 3135,
"item3": 3020,
"item6": 3340,
"item5": 3165,
"minionsKilled": 59,
"timePlayed": 2852,
"physicalDamageDealtToChampions": 1025,
"championsKilled": 5,
"trueDamageTaken": 377,
"goldSpent": 9620,
"neutralMinionsKilled": 3
},
"gameId": 107038398,
"ipEarned": 82,
"spell1": 3,
"teamId": 100,
"spell2": 7,
"gameMode": "CLASSIC",
"mapId": 11,
"level": 30,
"invalid": false,
"subType": "NORMAL",
"createDate": 1444289569012,
"championId": 99
}
]}
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