Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在调用API时以递归方式向参数发送输入_Java_Json - Fatal编程技术网

Java 如何在调用API时以递归方式向参数发送输入

Java 如何在调用API时以递归方式向参数发送输入,java,json,Java,Json,//如何用java编写这样发送输入的代码您可以在这些行中尝试一些东西。语法未经测试 //I have a property file which takes data for API //sendEmpData=ID,NAME,LNAME,Address how to send it with multiple request test_Iteration=3 parameterList=ID,NAME,Address parameterVal=1111,2222,333/AAA,B

//如何用java编写这样发送输入的代码

您可以在这些行中尝试一些东西。语法未经测试

 //I have a property file which takes data for API 
 //sendEmpData=ID,NAME,LNAME,Address  how to send it with multiple request 

test_Iteration=3
parameterList=ID,NAME,Address
parameterVal=1111,2222,333/AAA,BBB, ,/USA,,LON 

//I want to send the 3 inputs one by one as follows 
sendEmpData=1111,AAA,USA
sendEmpData=2222,BBB,null
sendEmpData=2222,BBB,LON
公共类searchOrgData扩展runautomationAPI
{
受保护的静态字符串searchDataAPIURL;
私有静态字符串行=”;
私有静态字符串缓冲区结果;
public void getOrgData()引发异常{
generateToken get_authenticationKey=new generateToken();
get_authenticationKey.getToken();
Properties prop=新属性();
InputStream InputStream=null;
inputStream=新文件inputStream(“config.properties”);
属性加载(输入流);
searchDataAPIURL=prop.getProperty(“searchDataAPIURL”);
//在此处创建字符串列表
List arrayList=新列表();
私有字符串[]test1={“123”,“ABC”,“USA”};
私有字符串[]test2={“”,“BGD”,“UK”};
add(test1);
add(test2);
for(字符串[]arr:arrayList)
{
字符串ID=arr[0];
字符串名称=arr[1];
字符串地址=arr[2];
JSONObject inputParameterList=新的JSONObject();
inputParameterList.put(“ID”,ID));
inputParameterList.put(“名称”,名称);
inputParameterList.put(“地址”,地址);
字符串jsonData=inputParameterList.toString();
searchOrgData httpPostReq=新的searchOrgData();
HttpPost HttpPost=httpPostReq.createConnectivity(searchDataAPIURL);
httpPostReq.executeReq(jsonData,httpPost);}
HttpPost createConnectivity(字符串restUrl){
HttpPost=新的HttpPost(restUrl);
setHeader(“内容类型”、“应用程序/json”);
post.setHeader(“接受”、“应用程序/json”);
post.setHeader(“授权”、“承载”+访问密钥);
回程站;
}
} 
}

请您在这里再详细说明一下……创建列表后,我有不同参数的不同输入场景,并调用每个参数的请求,因此您创建了数组列表。使用一次测试的数据创建阵列。然后将该数组添加到列表中。当您运行foreach循环时,您可以获取并保存每个数组的输出/返回(测试数据)。我已经更新了我的问题我已经更新了答案。问题是要知道,如何以迭代模式向API发送请求。
public class searchOrgData extends runautomationAPI
{
protected static String searchDataAPIURL;
private static String line="";
private static StringBuffer result;
public void getOrgData() throws Exception{
generateToken get_authenticationKey = new generateToken();
get_authenticationKey.getToken();
Properties prop = new Properties();
InputStream inputStream  = null;
inputStream  = new FileInputStream("config.properties");
prop.load(inputStream );
searchDataAPIURL = prop.getProperty("searchDataAPIURL");

//Create a list of strings here
List<String[]> arrayList = new List<String[]>();
private String[] test1= {"123", "ABC", "USA"};
private String[] test2= {"", "BGD", "UK"};
arrayList.add(test1);
arrayList.add(test2);

for (String[] arr : arrayList)
{
string ID= arr[0]; 
string name= arr[1]; 
string address= arr[2]; 
JSONObject inputParameterList=new JSONObject();
inputParameterList.put("ID", ID));
inputParameterList.put("Name", name);
inputParameterList.put("Address", address);
String jsonData=inputParameterList.toString();
searchOrgData httpPostReq=new searchOrgData();
HttpPost httpPost=httpPostReq.createConnectivity(searchDataAPIURL);
httpPostReq.executeReq( jsonData, httpPost);}
HttpPost createConnectivity(String restUrl){
HttpPost post = new HttpPost(restUrl);
post.setHeader("Content-Type", "application/json"); 
post.setHeader("Accept", "application/json");
post.setHeader("Authorization","Bearer "+ access_key);
return post;
}
} 
}