lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Thanks, this one satisfies the conditions. Unfortunately, it is
too strict for the JSON produced by the webpage. Example:
   [{"items":[];"date": "2017-04-15"}]
   nil    Missing a comma or '}' after an object member. (12)
I'm not a JSON expert, so can't comment on the validity of the
original string, but I have no control over the webpage that
produces it.

In the meantlime, by Murphy's Law, the PHP page has thrown up
an nested list, so the fallback decoder is now:

 function json_decode (s)
    local function do_json_list(s,is_list)
      if is_list then s = s:sub(2,-2) end
      s = s:gsub("(%b[])()",do_json_list)
      if is_list then s = '{' .. s ..'}' end
      return s
    local t = load('return '..do_json_list(s):gsub('("[%w_-]-"):','[%1]='))
    if t then return t() else return s end

2017-04-15 14:51 GMT+02:00 Xpol Wan <>:
> There is my binding to rapidjson:
> Or just luarocks install rapidjson
> 云风 Cloud Wu <>于2017年4月15日 周六下午4:40写道:
>> Dirk Laurie <>于2017年4月15日周六 上午5:45写道:
>>> I used to like lua-cjson but it does not sit well with Lua 5.3.
>>> Whenever a string could represent a number, it converts
>>> it to a float, so that every integer prints with a .0 at the end.
>>> Any recommendations for a module that works under Lua 5.3
>>> and does not have this annoying feature?
>> You can use my fork :
>> My pull request :