-1

I am having some problems with fetching a JSON file using HTTP:retry (or any of the other methods). The JSON file ends up looking like the picture below when I do ->body(); and then dd() it:

dd() of get result

I have attempted to do some cleaning with preg_replace (but not so good at regex), seems to partially work:

preg_replace( "/\r|\n/", "", $data );

Because the JSON looks like this it is not possible to do ->json(); it just returns null when I then dd() it. How can I can "clean" this properly so the result can be accessed as a normal JSON file?

Here is the output in text (missing the newlines (\n):

b"""
{
"devname":"Event Telt",
"devsn":"18940256",
"time":"14:54:53 2020-07-18",
"timeunix":"1595084093",
"synch":"1",
"ch1":
{
 "name":"Temp Dataskap",
 "unit":"°C",
 "aval":"19.1",
 "alarm":0
},
"ch2":
{
 "name":"Temp Rom",
 "unit":"°C",
 "aval":"17.4",
 "alarm":0
},
"ch3":
{
 "name":"Fukt Rom",
 "unit":"%RH",
 "aval":"77.0",
 "alarm":1
},
"ch4":
{
 "name":"Channel 4",
 "unit":"",
 "aval":"n/a",
 "alarm":0
},
"ch5":
{
 "name":"Channel 5",
 "unit":"",
 "aval":"n/a",
 "alarm":0
}
}
"""
halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

Problem finally solved,

It seems like the problem was malformed UTF-8 or something (See this answer: PHP json encode - Malformed UTF-8 characters, possibly incorrectly encoded)

It was fixed with this simple oneliner: mb_convert_encoding($temps->body(), 'UTF-8', 'UTF-8').

It seems like the special chars and weird addons in the dump was a side effect of how laravel displays stuff after a dd()

Thank you everyone for your suggestions!