This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Help decoding JSON data from socket.http.request
#4
(02.11.2017, 06:55)admin Wrote: Try running this then post both log entries. What it looks like is that the response is incorrect. JSON functions expect valid input which does not have "Content-Type" set anywhere so it's not the problem.

Code:
require('json')
require('socket.http')

url = 'http://192.168.1.xx/inst.json'
data = socket.http.request(url)

log(data)
log(json.pdecode(data))

Here is the log entries I got :

Code:
Ecocompteur 02.11.2017 07:58:47
* string: {
   "data1":195.000000,
   "data2":0.000000,
   "data3":0.000000,
   "data4":173.000000,
   "data5":0.000000,
   "data6":0.000000,
   "data6m3":0.000000,
   "data7":0.000000,
   "data7m3":0.000000,
   "heure":7,
   "minute":58
}HTTP/1.0 200 OK
Server: lwip/3.0
Content-Type: text/plain

{
   "data1":195.000000,
   "data2":0.000000,
   "data3":0.000000,
   "data4":173.000000,
   "data5":0.000000,
   "data6":0.000000,
   "data6m3":0.000000,
   "data7":0.000000,
   "data7m3":0.000000,
   "heure":7,
   "minute":58
}
Ecocompteur 02.11.2017 07:58:47
* arg: 1
 * nil
* arg: 2
 * string: Expected the end but found invalid token at character 253

(I PM you more info)
Thx

(01.11.2017, 21:50)Erwin van der Zwart Wrote: Hi,

Try  this:
Code:
if type(response_body) == 'table' then
  data = json.pdecode(table.concat(response_body))
else
  data = json.pdecode(response_body)
end
log(data)
BR,

Erwin

Thx Erwin, but it does not work.
Here is the log entry :

Ecocompteur 02.11.2017 08:33:27
* nil
Reply


Messages In This Thread
RE: Help decoding JSON data from socket.http.request - by mooselight - 02.11.2017, 07:00

Forum Jump: