Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

Commit 86bcb95

Browse files
committed
在http_test.cn中导入JSON库并添加多个JSON操作示例,包括创建对象、数组、合并对象、提取值和有效性检查,扩展了HTTP测试功能。
1 parent 6f97e06 commit 86bcb95

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

examples/http_test.cn

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// 导入HTTP库
1+
// 导入HTTP库和JSON库
22
using lib <http>;
3+
using lib <json>;
34
using lib <io>;
45
using ns std;
56

@@ -23,5 +24,34 @@ fn main() : int {
2324
decoded : string = http::decode_url(encoded);
2425
println("URL解码结果: " + decoded);
2526

27+
// 使用JSON库解析HTTP响应
28+
println("\n===== JSON库测试 =====");
29+
30+
// 创建JSON对象
31+
json_obj : string = json::create_object("name", "张三", "age", "25", "city", "北京");
32+
println("\n创建的JSON对象:");
33+
println(json::format(json_obj));
34+
35+
// 创建JSON数组
36+
json_arr : string = json::create_array("苹果", "香蕉", "橙子", "葡萄");
37+
println("\n创建的JSON数组:");
38+
println(json_arr);
39+
40+
// 合并JSON对象
41+
address : string = json::create_object("country", "中国", "province", "北京");
42+
merged : string = json::merge(json_obj, address);
43+
println("\n合并后的JSON对象:");
44+
println(json::format(merged));
45+
46+
// 测试从对象中提取值
47+
name_value : string = json::get_value(json_obj, "name");
48+
println("\n提取的name值:");
49+
println(name_value);
50+
51+
// 测试检查JSON是否有效
52+
is_valid : string = json::is_valid(json_obj);
53+
println("\nJSON是否有效:");
54+
println(is_valid);
55+
2656
return 0;
2757
};

0 commit comments

Comments
 (0)