web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavJsonToken to Microsoft.Dynamics.Nav.

(1) ShareShare
ReportReport
Posted on by 153
Hi Guys,
 
I am facing this error.
Error: Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavJsonToken to Microsoft.Dynamics.Nav.Runtime.NavJsonObject.
Is any way to solve this problem.
 
  • IB-29041624-0 Profile Picture
    1,191 Moderator on at
    Maybe you can share the code that is failing?
    I belive it will be easier to assist you if we can have a look at your code.
  • KK-20050817-0 Profile Picture
    72 on at
     // Iterate over attributes to find currency and rate
                            for i := 1 to xmlAttrCol.Count do begin
                                if xmlAttrCol.Get(i, xmlAttr) then begin
                                    // GPT comment: xmlAttr is initialized from xmlAttrCol.Get(i, xmlAttr)
     
                                    // Check for 'currency' attribute
                                    if xmlAttr.Name = 'currency' then
                                        TargetCurrency := xmlAttr.Value;
     
                                    // Check for 'rate' attribute
                                    if xmlAttr.Name = 'rate' then
                                        if Evaluate(Rate, xmlAttr.Value) then begin
                                            // Check if the target currency is one of our desired target currencies
                                            if TargetCurrencies.Contains(TargetCurrency) then begin
                                                // Insert or update the exchange rate in Currency Exchange Rate table
                                                if CurrencyExchangeRate.Get('EUR', TargetCurrency, Today) then begin
                                                    CurrencyExchangeRate.Validate("Exchange Rate Amount", Rate);
                                                    CurrencyExchangeRate.Modify();
                                                end else begin
                                                    CurrencyExchangeRate.Init();
                                                    CurrencyExchangeRate.Validate("Currency Code", TargetCurrency);
                                                    CurrencyExchangeRate.Validate("Starting Date", Today);
                                                    CurrencyExchangeRate.Validate("Exchange Rate Amount", Rate);
                                                    CurrencyExchangeRate.Insert();
                                                end;
                                                Message('I m inside 2 cu');
                                            end;
                                        end else
                                            Error('Failed to convert rate for %1', TargetCurrency);
                                end;
                            end;
                            XmlElement := gXmlNode.AsXmlElement(); // GPT comment: Initialize XmlElement from gXmlNode
                        end;
  • Suggested answer
    Chavda Dharmendra Profile Picture
    1,004 Super User 2026 Season 1 on at
    I deserialize the JSON file into a JSON token, and then into an array and object.
     
     
    local procedure ShippingAddress(ResponseText: Text)
        var
            JToken: JsonToken;
            JLinesToken: JsonToken;
            JObject: JsonObject;
            ValueObject: JsonObject;
            Jarray: JsonArray;
            i: Integer;
        begin
            JToken.ReadFrom(ResponseText);
            JObject := JToken.AsObject();
            if JObject.SelectToken('$.value', JLinesToken) then begin
                Jarray := JLinesToken.AsArray();
                for i := 0 TO (Jarray.Count - 1) do begin
                    Jarray.Get(i, JLinesToken);
                    ValueObject := JLinesToken.AsObject();
                    SetShipping(ValueObject); //Create Shipping Address
                end;
            end else begin
                SetShipping(JObject);
            end;
        end;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 743 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 546 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 332 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans