Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
314e4e76
J
json
项目概览
畅游知识海洋
/
json
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
json
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
314e4e76
编写于
12月 16, 2017
作者:
N
Niels Lohmann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
📝
improved documentation for dump and iterator_wrapper
上级
9a51fb4d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
57 addition
and
5 deletion
+57
-5
doc/examples/dump.cpp
doc/examples/dump.cpp
+11
-0
doc/examples/dump.link
doc/examples/dump.link
+1
-1
doc/examples/dump.output
doc/examples/dump.output
+1
-0
src/json.hpp
src/json.hpp
+44
-4
未找到文件。
doc/examples/dump.cpp
浏览文件 @
314e4e76
...
...
@@ -28,4 +28,15 @@ int main()
std
::
cout
<<
"strings:"
<<
'\n'
<<
j_string
.
dump
()
<<
'\n'
<<
j_string
.
dump
(
-
1
,
' '
,
true
)
<<
'\n'
;
// create JSON value with invalid UTF-8 byte sequence
json
j_invalid
=
"
\xF0\xA4\xAD\xC0
"
;
try
{
std
::
cout
<<
j_invalid
.
dump
()
<<
std
::
endl
;
}
catch
(
json
::
type_error
&
e
)
{
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
}
}
doc/examples/dump.link
浏览文件 @
314e4e76
<a target="_blank" href="https://wandbox.org/permlink/UnV6etCOZZRZpYyB"><b>online</b></a>
\ No newline at end of file
<a target="_blank" href="https://wandbox.org/permlink/mHH9TibITCYPpLwy"><b>online</b></a>
\ No newline at end of file
doc/examples/dump.output
浏览文件 @
314e4e76
...
...
@@ -50,3 +50,4 @@ arrays:
strings:
"Hellö 😀!"
"Hell\u00f6 \ud83d\ude00!"
[json.exception.type_error.316] invalid UTF-8 byte at index 3: 0xC0
src/json.hpp
浏览文件 @
314e4e76
...
...
@@ -11297,22 +11297,62 @@ class basic_json
reference to the JSON values is returned, so there is no access to the
underlying iterator.
For loop without iterator_wrapper:
@code{cpp}
for (auto it = j_object.begin(); it != j_object.end(); ++it)
{
std::cout << "key: " << it.key() << ", value:" << it.value() << '\n';
}
@endcode
Range-based for loop without iterator proxy:
@code{cpp}
for (auto it : j_object)
{
// "it" is of type json::reference and has no key() member
std::cout << "value: " << it << '\n';
}
@endcode
Range-based for loop with iterator proxy:
@code{cpp}
for (auto it : json::iterator_wrapper(j_object))
{
std::cout << "key: " << it.key() << ", value:" << it.value() << '\n';
}
@endcode
@note When iterating over an array, `key()` will return the index of the
element as string (see example).
@param[in] ref reference to a JSON value
@return iteration proxy object wrapping @a ref with an interface to use in
range-based for loops
@liveexample{The following code shows how the wrapper is used,iterator_wrapper}
@exceptionsafety Strong guarantee: if an exception is thrown, there are no
changes in the JSON value.
@complexity Constant.
@note The name of this function is not yet final and may change in the
future.
*/
static
iteration_proxy
<
iterator
>
iterator_wrapper
(
reference
cont
)
static
iteration_proxy
<
iterator
>
iterator_wrapper
(
reference
ref
)
{
return
iteration_proxy
<
iterator
>
(
cont
);
return
iteration_proxy
<
iterator
>
(
ref
);
}
/*!
@copydoc iterator_wrapper(reference)
*/
static
iteration_proxy
<
const_iterator
>
iterator_wrapper
(
const_reference
cont
)
static
iteration_proxy
<
const_iterator
>
iterator_wrapper
(
const_reference
ref
)
{
return
iteration_proxy
<
const_iterator
>
(
cont
);
return
iteration_proxy
<
const_iterator
>
(
ref
);
}
/// @}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录