[英]how to return data in json format to javascript ajax call
I have the following method: 我有以下方法:
public String getUTResult() throws IOException {
BuildResultParser bp = new BuildResultParser();
BuildResultBean b = bp.getreadFile("C:\\bc.txt");
String str = b.getuTresult();
return str;
Now str
variable contains the value as: [0,5,5]
现在
str
变量包含的值为: [0,5,5]
Now I need to pass this value to ajax call in javascript in following format: 现在,我需要将该值传递给javascript中的ajax调用,格式如下:
unittest
{
fail:0
pass:5
total:5
}
Actually in javascript, I need this data in array format so that I can access each value and do some processing. 实际上,在javascript中,我需要使用数组格式的数据,以便可以访问每个值并进行一些处理。
Read this : http://hmkcode.com/java-servlet-send-receive-json-using-jquery-ajax/ or any example of converting data to json format. 阅读以下内容: http : //hmkcode.com/java-servlet-send-receive-json-using-jquery-ajax/或将数据转换为json格式的任何示例。
If your requirement is limited to the example, u can have another function which takes str and creates json data out of it, in the format required by you. 如果您的要求仅限于示例,则可以使用另一个函数,该函数采用str并以您要求的格式从其中创建json数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.