Re: [Cppcms-users] access JSON array through path
Brought to you by:
artyom-beilis
|
From: Artyom B. <art...@ya...> - 2014-11-09 07:40:14
|
No it does not work like this. Also adding it is possible it would be quite sub-optimal as forexample the search for "foo.bar.baz" does virtually without any parsing or memory allocation.
So if get "foo.bar[5].baz" you'll need to first format a string with a number and let the json::value::get parse the number.
It is better to use:
at("foo.bar")[5].get("baz")
In your case:
at("path.some_array")[2][2].at("deeply_nested")[0].get("foo",...)
This would actually be efficient.
Artyom Beilis
--------------
CppCMS - C++ Web Framework: http://cppcms.com/
CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
From: miniME <min...@go...>
To: cpp...@li...
Sent: Saturday, November 8, 2014 11:50 PM
Subject: [Cppcms-users] access JSON array through path
Hey,
is it possible to specify the path to a specific array value?
(see the "cppcms::json::value::get" method)
consider the following JSON:
{
"path": {
"some_array": [
"val1",
"val2",
[
"nested_array1_val1",
"nested_array1_val2",
{
"deeply_nested" : [
"foo"
]
}
]
]
}
}
I would expect to use the path including array values as following:
"path.some_array[0]" --> "val1"
"path.some_array[1]" --> "val2"
"path.some_array[2]" --> array
even nested:
"path.some_array[2][1]" --> "nested_array1_val2"
"path.some_array[2][2].deeply_nested[0]" --> "foo"
It is not documented and doesn't work like this. Is there some easy way to achive this?
------------------------------------------------------------------------------
_______________________________________________
Cppcms-users mailing list
Cpp...@li...
https://lists.sourceforge.net/lists/listinfo/cppcms-users
|