You are not logged in.
Pages: 1
Hi,
I'm doing this:
const
__MyJSON ='{"waypoints":[{"location":[14.723485,-17.443965],"name":"C46","hint":"m88zgO2Ev4BsywcAtAkAAEQBAACiCAAAXUoAANkSIADlBQAAnangAIPT9f5RnOAAqnT1_gQAAQHOiWch"},' +
'{"location":[14.759195,-17.448485],"name":"C46","hint":"m88zgO2Ev4BsywcAvgMAAF8CAADuGAAA7D4AANkSIADlBQAAGzXhANvB9f6GOOEAz9r1_gcAAQHOiWch"}],' +
'"routes":[{"distance":3822.4,"duration":264.6,"legs":[{"distance":3822.4,"duration":264.6,"summary":"","steps":[]}],"geometry":"x_niBytzxAf[e~E"}],"code":"Ok"}';
procedure TForm1.btnParseClick(Sender: TObject);
var doc : Variant;
R:Double;
begin
doc := _JsonFast(__MyJSON);
R := TDocVariantData(doc).GetValueByPath(['routes','duration']);
end;
Result(R) is 0.
How can I get duration value?
Thanks.
Offline
Routes is an array, which item (position) of the array are you targeting ?
Offline
Thanks for the answer.
I'm sorry I don't understand the question (I'm playing with JSON and Mormot for the first time). My objective is to get distance and duration values from this Json string I provided. Maybe I'm supposed to answer "First position".
I would like to get distance = 3822.4 and duration = 264.6
I'm trying to use TDocVariantData like in the mORMot documentation because I really like the way it is done (smart and simple without using class or record definition and blazing fast).
From your answer I understand it cannot work without giving the position of the item inside the array. How to do it?
Offline
Arrays are not allowed in paths.
Try this:
R := doc.routes._(0).duration;
Last edited by jbroussia (2016-11-19 20:21:32)
Offline
This is it!!
Thank you very much.
Offline
Very much like to main question, How can I read first set of "rings" in below Json?
{
"name": "OBJECTID",
"FieldName": "",
"Type": "Polygon",
"fields": [
{
"name": "GID",
"alias": "GID",
"type": "FieldTypeInteger"
}
],
"features": [
{
"attributes": {
"GID": 32289
},
"geometry": {
"rings": [
[
[
47.213439779999987,
41.039492069999994
],
[
47.213007080000011,
41.039838900000007
]
]
]
}
}
}
What I wrote and didn't work is something like:
procedure TForm1.Button1Click(Sender: TObject);
var
Json: string;
Value: Variant;
begin
Json := Memo1.Text;
Value := _JsonFast(RawUtf8(Json));
Label1.Caption := Value.rings._(0);
end;
Error I receive is invalid variant operation.
Thanks.
Offline
Pages: 1