私はアスタリスクpbxでluaを使用しています。 json文字列を処理しているときに次の問題が発生しました。luaを使用してjson文字列内でnull値を処理する方法は?
json "null"値がルアの関数型に変換されました。どうして?
このシナリオをどのように扱うか?なぜなら、jsonでは値がnullを意味し、nuaではluaでは何も意味しないため、私はnilを期待しているからです。うち上記のために入れ
local json = require("json")
local inspect = require("inspect")
local myjson_str='{"Sms":{"key":"xxxxxxxxxxxxxxxxxxxxx","to":"{caller}","senderid":null,"type":"Simple","content":"Your request has been accepted in Previous Miss call. We get back to you very soon."}}'
local myjson_table = json.decode(myjson_str)
print(type(myjson_table["Sms"]["senderid"]))
print(myjson_table)
print(inspect(myjson_table))
print(json.encode(myjson_table))
それはnull
値を表現する方法を決定するために、特定のライブラリに任されて
function
table: 0xf5e770
{
Sms = {
content = "Your request has been accepted in Previous Miss call. We get back to you very soon.",
key = "xxxxxxxxxxxxxxxxxxxxx",
senderid = <function 1>,
to = "{caller}",
type = "Simple"
}
}
{"Sms":{"type":"Simple","key":"xxxxxxxxxxxxxxxxxxxxx","senderid":null,"content":"Your request has been accepted in Previous Miss call. We get back to you very soon.","to":"{caller}"}}
json.util.nullは、最後に見つかった関数です。私は同じように処理することができます。あなたのポイントは、使用しているライブラリ/言語に依存しています。 – rajesh6115