Invalid JSON passed in frame

This bug or something I just cant figured it out how to solve this what is the problem when I sendnuimessage it just saying SEND_NUI_MESSAGE : invalid JSON passed in frame This This why


Here is a code part

function StartMeter()

SendNuiMessage({show = true})

InRoute = true

local Player = PlayerPedId()

local Sec = 0

local TotalDistace = 0

Citizen.CreateThread(function()

    while InRoute and InTaxi do

        local Dist2 = GetEntityCoords(Player)

        Citizen.Wait(1000)

        local Dist1 = GetEntityCoords(Player)

        local DistanceTravelin1sec =

            math.floor(GetDistanceBetweenCoords(Dist2, Dist1, true))

        TotalDistace = TotalDistace + DistanceTravelin1sec

        Sec = Sec + 1

        local Fare = math.floor(TotalDistace / 100) * 35

        local Minutes = math.floor(Sec / 60)

        SendNUIMessage({

            Fare = Fare,

            Sec = Minutes,

            TotalDistace = 0,

            data = true

        }) 

    end

end)

end

Haven’t used NUI in a while, but I believe you need to encode the message your sending using JSON, like this:

SendNUIMessage(json.encode({
    Fare = Fare,
    Sec = Minutes,
    TotalDistace = 0,
    data = true
})) 
5 Likes

Thank a lot that is working!!!