Hi,
How can I use code written in C# in Oxygene (word dynamic) ?
var serializer = new JavaScriptSerializer();
var dict = serializer.Deserialize<dynamic>(aJSONData);
return dict[aJSONParameter].ToString();
Best regards
Mateusz
Hi,
How can I use code written in C# in Oxygene (word dynamic) ?
var serializer = new JavaScriptSerializer();
var dict = serializer.Deserialize<dynamic>(aJSONData);
return dict[aJSONParameter].ToString();
Best regards
Mateusz
Oxygene supports the “dynamic” type same as C#, with the “dynamic” keyword. So the above code should works is (adjusted to Oyxgene syntax, of course).
Oxidizer made code like this, but it doesn’t work - (E28) Unknown type “dynamic”:
namespace WCF_JSONReader;
interface
uses
System,
System.Collections.Generic,
System.Linq,
System.Text,
System.Threading.Tasks,
System.Web.Script.Serialization,
RemObjects.Elements.System;
type
JSONReader = public class
public
class method GetDataFromJSON(aJSONData: String; aJSONParameter: String): String;
end;
implementation
class method JSONReader.GetDataFromJSON(aJSONData: String; aJSONParameter: String): String;
begin
//JSON deserialization http://procbits.com/2011/04/21/quick-json-serializationdeserialization-in-c
var serializer := new JavaScriptSerializer();
var dict := serializer.Deserialize<&dynamic>(aJSONData);
exit dict[aJSONParameter].ToString()
end;
end.
Remove the &, dynamic is a keyword.
I’ve tried without and I get - Error 2 (E1) semicolon ( expected, got “dynamic”
You can’t create a dynamic, it needs to be something else and then cast as a dynamic
var serializer := new JavaScriptSerializer();
var dict:dynamic := serializer.Deserialize<ExpandoObject>(aJSONData);
exit dict[aJSONParameter].ToString()
It works thank you.
Best regards
Mateusz
Hmm, odd that that works in C# then?
In C# it works…
Thanks, logged as bugs://69788: Cannot use “Dynamic” in generic parameter
bugs://69788 got closed as fixed