JSON格式用于数据传输、bean用于封装数据信息、String用于展示封装信息、json格式的内容用json工具或者之间在json.cn展示比较清晰。

一、将Sting转为Json

在开发中,经常是前端发送一串数据过来之后,是通过一个参数带着一串值过来,这一串值是String 格式的,但是里面的内容其实是json格式类型的,所以拿到值之后就要将该值转化成json格式,然后获取里面指定的key就可以拿到该值了。JSONObject jsonObject = JSON.parseObject(tt);

这样就可以将一串参数转化成json对象了,然后通过下面指定的key获取特定的值,如下面所示String imei= (String) jsonObject.get("imei");

在返回数据中,要经常返回指定的json格式,我用的是如下所示:Mapmap=new HashMap<>();

map.put("ret",1);

map.put("ret1","no");

json
适用于现代 C++ 的 JSON。

map.put("tag1",sh.getTOpen());

map.put("video",sh.getfOpen());

map.put("video1",sh.getVOpen());

map.put("video2",sh.getViOpen());

String json=JSON.toJSONString(map);

然后return json;就可以了,不过一般这个值是要加密之后再上传给前端的。

GitHub 加速计划 / js / json
45
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:6 个月前 )
96c1b52f * :alembic: remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional) Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :alembic: remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional) Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :alembic: remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional) Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :alembic: remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional) Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :alembic: remove JSON_USE_IMPLICIT_CONVERSIONS check for from_json(json, std::optional) Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :alembic: add C++ standard library as matrix option Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :rewind: remove inline Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> 1 天前
4cca3b9c * :rotating_light: fix warning Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :construction_worker: add emscripten Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :construction_worker: add emscripten Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :construction_worker: add emscripten Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :construction_worker: add emscripten Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :construction_worker: add emscripten Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :construction_worker: add emscripten Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :construction_worker: add emscripten Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :construction_worker: add emscripten Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :construction_worker: add emscripten Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :memo: add compiler to list Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> 3 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐