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

Notifications

Announcements

No record found.

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.
 
I have the same question (0)
  • Inge M. Bruvik Profile Picture
    1,105 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,000 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,226

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,047 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,257 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans