I'm getting an error when using Deserializer.FromJson(JsonObject, TObject); JsonObject is a list of objects.
I check now if JsonObject is TJSONArray and then use Result := Deserializer.FromJson(JsonObject, TList<TObject>);
Is this the right way to do?
FDeserializer.ProxyLoader := TJsonProxyLoader.Create( function(ProxyInfo: IProxyInfo): TObject var Serializer: TDataSnapJsonSerializer; Deserializer: TDataSnapJsonDeserializer; JsonObject: TJsonValue; begin Serializer:= TDataSnapJsonSerializer.Create; Deserializer := TDataSnapJsonDeserializer.Create;
try JsonObject := FClient.RemoteProxyLoad(Serializer.ToJson(ProxyInfo)); if JsonObject is TJSONArray then begin Result := Deserializer.FromJson(JsonObject, TList<TObject>); end else begin Result := Deserializer.FromJson(JsonObject, TObject); end; finally Deserializer.Free; Serializer.Free; end; end );
--------------------------- Debugger Exception Notification --------------------------- Project Client.exe raised exception class EIncompatibleJsonValueType with message 'Incompatible json value. Cannot serialize to the proper type. (Instance): Not a JSON Object nor null'. --------------------------- Break Continue Help ---------------------------
But now I check if JsonObject is a list like:
if JsonObject is TJSONArray then begin Result := Deserializer.FromJson(JsonObject, TList<TObject>); end else begin Result := Deserializer.FromJson(JsonObject, TObject); end;
Your error message indicates that it's expecting a JSON object, but it's not. Are you sure your JSON Array contains objects (and not other JSON types)? You just need to check your JSON to see if it matches what the framework is expecting.