How to get TJSONValue Type

Hi,

How can i get the type of tjsonvalue, for know if a tjsonvalue is a tjsonarray or tjsonobject or tjsonstring ?

I try use this syntax like in vcl with system.json:

function TMyObject.GetTypeJS(tjs: TJSONValue): String;
begin
if tjs is TJSONObject then result:='object';
if tjs is TJSONArray then result:='array';
if tjs is TJSONString then result:='string';
end;

But no operator is seems not run with weblib.json

How can i make this ?

Thanks

I cannot see an issue.
Test code:

uses
  WEBLib.JSON;

function GetJSONTypeJS(tjs: TJSONValue): String;
begin
if tjs is TJSONObject then result:='object';
if tjs is TJSONArray then result:='array';
if tjs is TJSONString then result:='string';
end;


procedure TForm1.WebButton1Click(Sender: TObject);
var
  jo: TJSONObject;
  ja: TJSONArray;
  s: string;
begin
  jo := TJSONObject.Create;

  s := GetJSONTypeJS(jo);
  console.log(s);

  ja := TJSONArray.Create;

  s := GetJSONTypeJS(ja);
  console.log(s);
end;

Hi Bruno,

Thanks for your response.

This code runs ok. But the problem seems to be when the TJSONValue is a TJSONPair.JsonValue

In my project i need to know a TJSON Type of TJSONPair.JsonValue.

When the function GetJSONTypeJS runs under VCL it runs ok in both cases, passing TJSONValue ans passing TJSONPair.JsonValue...

But under Web only runs if passing YJSONValue, but not passing TJSONPair.JsonValue.

If you want, you can try this using a example project you can download with this link:

https://cloud.maddinformatics.com/owncloud/index.php/s/jNnoLmwvbTBqBcU/download

`The question is how can i know the type os
TJSONPair.JsonValue under Web environment...

    Thanks`

Hi Bruno,

I'm updated the example of the isue... This is the link to download the test project.

https://cloud.maddinformatics.com/owncloud/index.php/s/r26SKv5uMsyzR4g/download

In this project there ara two buttons. In the example 2 (button 2) you can see that if i create a TJSONPair and i assign in your property JsonValue one TJSON Array...

TJSONPair.JsonValue:=TJSONArray;

When i inspect the jsontype of the TJSONPair.JsonValue response is 'array'... Is ok.

The problem are when i obtain JSON by jo:=TJSONObject.ParseJSONValue(String).

See example 1... The same that yesterday example....

It seems that the problem is in the WebLib.ParseJSONValue...

What can i do ?

Thanks
JSONTypeIssue.pdf (54.5 KB)

Hi,

Sorry but i need feedback about this issue.

Although the answer is that it is a problem that you are reviewing and for which you still do not have the solution.

I would like to use this mechanism to do what I need because that way I can share the logic with the VCL and FMX code but if it is not possible I would look for another way to do it. But I need to move on.

Thanks

You WILL get feedback.

A day for me has just like for you only 24hrs and I happen to be extremely busy with preparing the release of TMS WEB Core v2.1. So, please be patient till I can breathe again and investigate your question.

We could trace & solve this issue.
v2.1 will address this.