Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON decode is not working

Tags:

json

php

This is my 3.txt file: json file

I don't know why it works when it has only 1 data and when it has more data it's not working.

This is my code:

code

like image 452
Keerati Pongram Avatar asked Feb 12 '26 14:02

Keerati Pongram


1 Answers

Your 3.txt does not contain a valid json. You need to adjust your sample string to be valid JSON by adding quotes around strings, commas between objects and placing the objects inside a containing array (or object). It should be something like this,

 [{"address":"+6161616","body":"asda","date":"1231"},
{"address":"+616sdfs6","body":"as3sda","date":"155231"},
{"address":"+6161616","body":"asda","date":"123551"}]

You can test if a json is valid here.

like image 119
Abey Avatar answered Feb 14 '26 03:02

Abey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!