将动态生成的数据注入JSON [英] Inject dynamically generated data into JSON

查看:219
本文介绍了将动态生成的数据注入JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一种工具,可以测试对服务器的某些请求,这些请求本身不过是一些简单的JSON文件,这些文件存储在光盘上并且可以连续添加,但是……还有另外一件事, JSON文件包含一个电子邮件地址,每次运行该项目时都需要更改该电子邮件地址,这是因为每个用户都有一个私人电子邮件,我认为这是因为服务器不能接受来自一个用户的多个请求.因此,我正在寻找一种将此电子邮件地址动态注入JSON的解决方案.

I have developed a tool that can test some requests to a server, the requests themselves are no more than some simple JSON files that are stored on the disc and can be added continuously, but ... there is one more thing, the JSON files contains an e-mail address that needs to be changed upon running the project each time, this is because each of users have a personal e-mail, I made that because server can't accept more than one request from an user. So I am looking for a solution to inject this e-mail address dynamically into JSON.

为此,我正在使用Java,对于REST API,也使用jayway;对于JSON,也使用Gson.到目前为止,我调查了google,但根本找不到任何东西.

I'm using Java for this, and also jayway for REST API and Gson for JSONs. So far I looked into google, but can't find anything at all.

推荐答案

您可以通过以下解决方案来做到这一点:

You could do this by these solutions:

  • 使用json文件作为带有标记的模板字符串,例如"{email:$ {e-mail}}",然后只需使用jsonTemplate.replace("${e-mail}", email[i])
  • 将json解析为模型请求的Map或Object,然后更改电子邮件字段并再次从中构建json

这篇关于将动态生成的数据注入JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆