【发布时间】:2021-08-03 20:58:07
【问题描述】:
我有一个包含以下格式信息的字符串:
Maltese Age: 2 Price: $500
https://images.google/image
Staffy Age: 1 Price: $500
https://images.google/image
Yorkie Age: 2 Price: $300
https://images.google/image
我的目标是把上面的变成这样:
Dogs:
{
"dog": "Pomeranian",
"info": {
"url": "https://images.google.com/image",
"age": 2,
"price": 1000
}
当然,对于我在字符串中的所有宠物,我会在后面和第四个循环。
【问题讨论】:
-
你已经在使用任何 json 库了吗?
-
我正在使用 org.json,是的
-
使用正则表达式获取不同的组,并使用您的json库将结果转换为您描述的JSON对象。