Ambigouos call when using json
Sunset
Member Posts: 201
For a solution I have "borrowed" heavily from kaufmann on how to extract values from json.
For the modifications inside NAV (11.0.21441) everything has worked like a charm. Now the customer wants to upgrade, and we want to go full on extensions this time. However now the code is failing due to an ambigouos call when when using for instance DateTime. Does anybody know how I can restructure the code so that is could work again in 14.0.32615?
procedure GetValueAsDateTime(JObject: DotNet MyJObject; PropertyName: Text) ReturnValue: DateTime
var
DotNetDateTime: DotNet MyDateTime; //Defined in the dotnet.al file
CultureInfo: DotNet MyCultureInfo; //Not really neccesary here, but kept since it is in the original code
begin
DotNetDateTime := JObject.GetValue(PropertyName).ToObject(GETDOTNETTYPE(DotNetDateTime));
ReturnValue := DotNetDateTime;
end;
For the various other places in the code where it says DotNetBoolean.Parse(JObject.GetValue(PropertyName).ToString); it works fine, but for the .ToObject I am now getting an error "The call is ambiguous between the following methods or properties: 'ToObject(DotNet "Newtonsoft.Json.JsonSerializer")' and 'ToObject(DotNet "System.Type")'AL(AL0196)"
I can propably get it to work using the ToString, and then evaluating it. But I would prefer to get the correct type straight away. Please advice.
For the modifications inside NAV (11.0.21441) everything has worked like a charm. Now the customer wants to upgrade, and we want to go full on extensions this time. However now the code is failing due to an ambigouos call when when using for instance DateTime. Does anybody know how I can restructure the code so that is could work again in 14.0.32615?
procedure GetValueAsDateTime(JObject: DotNet MyJObject; PropertyName: Text) ReturnValue: DateTime
var
DotNetDateTime: DotNet MyDateTime; //Defined in the dotnet.al file
CultureInfo: DotNet MyCultureInfo; //Not really neccesary here, but kept since it is in the original code
begin
DotNetDateTime := JObject.GetValue(PropertyName).ToObject(GETDOTNETTYPE(DotNetDateTime));
ReturnValue := DotNetDateTime;
end;
For the various other places in the code where it says DotNetBoolean.Parse(JObject.GetValue(PropertyName).ToString); it works fine, but for the .ToObject I am now getting an error "The call is ambiguous between the following methods or properties: 'ToObject(DotNet "Newtonsoft.Json.JsonSerializer")' and 'ToObject(DotNet "System.Type")'AL(AL0196)"
I can propably get it to work using the ToString, and then evaluating it. But I would prefer to get the correct type straight away. Please advice.
Don't just take my word for it, test it yourself
0
Answers
-
And just for clarity. The dotnet.al contains
assembly("mscorlib")
{
Version = '4.0.0.0';
Culture = 'neutral';
PublicKeyToken = 'b77a5c561934e089';
type("System.DateTime"; MyDateTime { }
}
assembly("Newtonsoft.Json")
{
Version = '4.5.0.0';
Culture = 'neutral';
PublicKeyToken = '30ad4fe6b2a6aeed';
type("Newtonsoft.Json.Linq.JToken"; MyJToken) { }
type("Newtonsoft.Json.Linq.JObject"; MyJObject) { }
}
Don't just take my word for it, test it yourself0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions