Catchable fatal error: php json decode - php
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
Related
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
Why is there an error in myJson structure?
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!
Remove JSON Block with PHP
I have two JSON Files which I merge with a PHP Script. My PHP script looks like this: <?php header('Content-Type: application/json'); $a = file_get_contents("https://example.com/a.json", false); $b = file_get_contents("https://example.com/b.json", false); $merge = json_encode(array_merge( json_decode($a, true), json_decode($b, true) )); echo $merge; ?> My Output looks like this: [{ "id": 1141, "iid": 167, "project_id": 17, "title": "test", "description": "test", "state": "opened", "created_at": "2018-02-19T13:46:38.751Z", "updated_at": "2018-02-19T14:32:46.061Z", "closed_at": null, "labels": [], "milestone": null, "assignees": [], "author": { "id": 19, "state": "active" }, "assignee": null, "user_notes_count": 0, "upvotes": 0, "downvotes": 0, "due_date": null, "confidential": false, "discussion_locked": null, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null } }, { "id": 1140, "iid": 166, "project_id": 16, "title": "test2", "description": "test2", "state": "opened", "created_at": "2018-02-19T11:01:00.729Z", "updated_at": "2018-02-19T11:01:00.729Z", "closed_at": null, "labels": [], "milestone": null, "assignees": [{ "id": 5, "state": "active" }], "author": { "id": 5, "state": "active" }, "assignee": { "id": 5, "state": "active" }, "user_notes_count": 0, "upvotes": 0, "downvotes": 0, "due_date": null, "confidential": false, "discussion_locked": null, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null } }, { "id": 1136, "iid": 165, "project_id": 17, "title": "test3", "description": "test3", "state": "opened", "created_at": "2018-02-16T15:36:22.712Z", "updated_at": "2018-02-16T15:36:22.712Z", "closed_at": null, "labels": [], "milestone": null, "assignees": [{ "id": 5, "state": "active" }], "author": { "id": 1, "state": "active" }, "assignee": { "id": 5, "state": "active" }, "user_notes_count": 0, "upvotes": 0, "downvotes": 0, "due_date": null, "confidential": false, "discussion_locked": null, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null } }] Now I want to remove each block with "project_id": 16. How can i remove every Block with "project_id": 16? So i would like to remove this Block. And everyone else with "project_id": 16, if there were any more. { "id": 1140, "iid": 166, "project_id": 16, "title": "test2", "description": "test2", "state": "opened", "created_at": "2018-02-19T11:01:00.729Z", "updated_at": "2018-02-19T11:01:00.729Z", "closed_at": null, "labels": [], "milestone": null, "assignees": [{ "id": 5, "state": "active" }], "author": { "id": 5, "state": "active" }, "assignee": { "id": 5, "state": "active" }, "user_notes_count": 0, "upvotes": 0, "downvotes": 0, "due_date": null, "confidential": false, "discussion_locked": null, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null } }, I'm grateful for any help.
Here a little snippet $merge = array_filter($merge, function($item){ return $item['project_id'] != 16 })
How to remove index number from laravel eloquent unique
I am using a query that returns value perfectly but it adds key number to the collection. How can I remove the index number? Here is the retrieved data { "data": { "0": { "id": 135, "conversation_id": 11, "last_sender": null, "last_reciever": { "id": 54, "userName": "Sadek", "profilePic": "Nir7zgorNT2dmwcXJdhNK3ZmPAltmkEnj0SXDCDC.png", "firstName": "Sadek", "lastName": "Hossain" }, "msg": "hello guys how are you", "attachment": null, "deleted": 0, "seen": 0, "created_at": "2017-10-17 16:56:41", "updated_at": "2017-10-17 16:56:41" }, "2": { "id": 133, "conversation_id": 13, "last_sender": null, "last_reciever": { "id": 55, "userName": "buyer", "profilePic": "pRBDBFJW55baSnF560Ajid8jTgPo5kmg4i5LMhPG.jpeg", "firstName": "Matti", "lastName": "Rames" }, "msg": "second message 2 to user second", "attachment": null, "deleted": 0, "seen": 0, "created_at": "2017-10-17 15:43:14", "updated_at": "2017-10-17 15:43:14" } } } But I want to return results like this { "data": [ { "id": 133, "conversation_id": 13, "last_sender": null, "last_reciever": { "id": 55, "userName": "buyer", "profilePic": "pRBDBFJW55baSnF560Ajid8jTgPo5kmg4i5LMhPG.jpeg", "firstName": "Matti", "lastName": "Rames" }, "msg": "second message 2 to user second", "attachment": null, "deleted": 0, "seen": 0, "created_at": "2017-10-17 15:43:14", "updated_at": "2017-10-17 15:43:14" }, { "id": 135, "conversation_id": 11, "last_sender": null, "last_reciever": { "id": 54, "userName": "Sadek", "profilePic": "Nir7zgorNT2dmwcXJdhNK3ZmPAltmkEnj0SXDCDC.png", "firstName": "Sadek", "lastName": "Hossain" }, "msg": "hello guys how are you", "attachment": null, "deleted": 0, "seen": 0, "created_at": "2017-10-17 16:56:41", "updated_at": "2017-10-17 16:56:41" } ] } My query is (last few parts that I think is important) ->orderBy('created_at', 'desc') ->get() ->unique('conversation_id'); Please tell me how can I remove "0" and "2" from this collection.
In order to get a collection without a index you have to add the "values" method $collection->unique('id')->values();
You have to do it manually $users=\App\User::get()->toArray(); // your query here $data['data']=[]; foreach($users as $user ){ $data['data'][]=$user; } $k=json_encode($data); dd($k);
Getting data out of a JSON API with PHP
Im having trouble extracting data from a API, i would like to use for a school project.. The link to the API i here Or here's a sample of the API output { "help": "http://www.odaa.dk/api/3/action/help_show?name=datastore_search", "success": true, "result": { "resource_id": "2a82a145-0195-4081-a13c-b0e587e9b89c", "fields": [ { "type": "int4", "id": "_id" }, { "type": "text", "id": "date" }, { "type": "text", "id": "garageCode" }, { "type": "int4", "id": "totalSpaces" }, { "type": "int4", "id": "vehicleCount" } ], "records": [ { "date": "2015/11/11 03:50:07", "vehicleCount": 62, "_id": 1, "totalSpaces": 65, "garageCode": "NORREPORT" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 512, "_id": 2, "totalSpaces": 512, "garageCode": "SKOLEBAKKEN" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 236, "_id": 3, "totalSpaces": 1240, "garageCode": "SCANDCENTER" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 40, "_id": 4, "totalSpaces": 953, "garageCode": "BRUUNS" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 2932, "_id": 5, "totalSpaces": 142, "garageCode": "BUSGADEHUSET" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 18, "_id": 6, "totalSpaces": 383, "garageCode": "MAGASIN" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 3, "_id": 7, "totalSpaces": 210, "garageCode": "KALKVAERKSVEJ" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 255, "_id": 8, "totalSpaces": 700, "garageCode": "SALLING" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 0, "_id": 9, "totalSpaces": 0, "garageCode": "DOKK1" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 34, "_id": 10, "totalSpaces": 449, "garageCode": "Navitas" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 105, "_id": 11, "totalSpaces": 105, "garageCode": "NewBusgadehuset" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 9, "_id": 12, "totalSpaces": 319, "garageCode": "Urban Level 1" }, { "date": "2015/11/11 03:50:07", "vehicleCount": 15, "_id": 13, "totalSpaces": 654, "garageCode": "Urban Level 2+3" } ], "_links": { "start": "/api/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c", "next": "/api/action/datastore_search?offset=100&resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c" }, "total": 13 } } I would like to extract the cells called "vehicleCount" and "_id", but i seems I can't figure out how to do it :( $json = file_get_contents('http://www.odaa.dk/api/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c'); $json = json_decode($json); echo $json->fields->_id; I have tried many different ways, but now loss of ideas and its 4 o'clock in the morning, so hopefully someone can help me.
if you want to extract the cells vehicleCount and _id This is my solution for you: <?php $json = file_get_contents('http://www.odaa.dk/api/action/datastore_search?resource_id=2a82a145-0195-4081-a13c-b0e587e9b89c'); $json = json_decode($json); foreach ($json->result->records as $val) { echo "_id = " .$val->_id . " vehicleCount = " . $val->vehicleCount . "<br>"; } ?>
$json->result->records[0]->_id