服务器返回Json格式的响应内容经常是以 String (txt) 形式返回给客户端。客户端需要把 文本形式的内容还原为Json格式以进一步做处理(如,取得返回内容的一个值作为下个请求的一个输入)。这就要用到 一个函数 evel()。 具体做法如下:
 
Parsing the JSON Response
1. In the InitAgenda() function in the Agenda, define the global variable values of the SaveSource property as follows: 
function InitAgenda() 

    wlGlobals.SaveSource = true 

This instructs WebLOAD to store the complete HTML source code downloaded in the document.wlSource object.
 
2. Drag the JavaScript object Building Block from the Toolbox to the Agenda Tree. In  the Building Block, add a function that receives the document.wlSource object and manipulates it to retrieve the statistics. The script is as follows: 
function evalResponse ( source) {
    json_response = eval("(" + source + ")")
}
 
3. Call the evalResponse function to parse the response contents:
evalResponse(document.wlSource);
 
---------------------------------------具体做法是:-------------------------------
 
1. 把解析JSON 的函数 提取出来 放在一个单独的parseJSON.js文件里,以便重复利用:
function parseJSON(source){
    jsonResponse = eval("(" + source + ")");
    return jsonResponse;
}
 
2. 在脚本里引进 parseJSON.js 文件:
function InitAgenda()
{
    wlGlobals.SaveSource = true; 
    IncludeFile("FunctionLib\\parseJSON.js");  //IncludeFile 引进的文件是相对脚本wlp文件的位置;即这里的
                                                                  Function文件夹和wlp文件是放在同一个根目录下的
}
 
3. 直接引用parseJSON 文件里的函数:
 
var loginResponse = document.wlSource;
var loginObj = parseJSON(loginResponse);
var advisorId = loginObj.AdvisorId;
 
当然也可以不需要引进外部文件,而是直接把 eval()函数放在脚本里
 
注:JSON 节点的读取,如果是{}结构则 直接 a.b, 如果是[], 则 c[index].d 
 
如下面是一个返回的总结构:
{
"ReturnVsBenchmark": {},
"RiskReward": {},
"Portfolios": {},
"Information": {}
}

展开上面Portfolios 的层次结构如下:

"Portfolios": {
"Id": "Portfolios",
"Label": "Portfolios",
"Columns": [],
"Sections": [
{},
{},
{
"Rows": [
{
"Id": "95646f0f-879d-448b-8bf3-c9bcb15bedd0",
"Status": "Actual",
"OneYear": 0.13786034,
"ThreeYear": 0.14883958,
"FiveYear": 0.13716583,
"TenYear": 0.11452207,
"TrailingAsOfDate": "2014-10-31",
"MarketValue": 124809.13719108,
"MarketValueCurrencyCode": "USD",
"ThreeYearStdDev": 10.08655991,
"ThreeYearMean": 0.14883958,
"RiskRewardAsOfDate": "2014-10-31",
"AccountName": "Portfolio 1",
"YTD": 0.09898687,
"ReturnDate": "2014-10-31"
},
{},
{}
]
},
{},
{}
]
},

要取得 "Id"的值"95646f0f-879d-448b-8bf3-c9bcb15bedd0"  ,则读取的脚本如下:

var clientResponse = document.wlSource;  // 把 返回的内容存放一个变量中
var clientObj = eval( "(" + clientResponse + ")" );  // 把返回的txt 格式的内容转化为JSON 格式
var portfolioId1 = clientObj.Portfolios.Sections[2].Rows[0].Id; //Sections[2]取得是Rows 这个对象,在Sections[]里, 每个{}对象都是Sections 对象数组的一个元素

WebLoad 解析服务器返回的JSON格式内容的更多相关文章

  1. WebLoad 解析服务器返回的XML格式内容

    Parsing the XML Response get the root node:  var rootNode = document.wlXmls[0].XMLDocument.documentE ...

  2. javascript解析从服务器返回的json格式数据

    在javascript中我们可以将服务器返回的json格式数据转换成json格式进行使用,如下: 1.服务器返回的json格式数据: 通过response.responseText获得: " ...

  3. ajaxFileUpload上传文件成功后却无法解析服务器返回的json数据

    可能是应该返回内容带了标签,过滤下 var index=data.indexOf("<"); if (index!=-1){ data=data.substring(0,in ...

  4. 在C#中通过使用Newtonsoft.Json库来解析百度地图地理编码(GeoCoder)服务接口返回的Json格式的数据

    百度地图地理编码(GeoCoder)服务接口返回的Json格式的数据,如下所示: http://api.map.baidu.com/geocoding/v3/?address=**省**市**区**路 ...

  5. JS前端取得并解析后台服务器返回的JSON数据的方法

    摘要:主要介绍:使用eval函数解析JSON数据:$.getJSON()方法获得服务器返回的JSON数据 JavaScript eval() 函数 eval(string) 函数可计算某个字符串,并执 ...

  6. [转]android中解析后台返回的json字符串

    普通形式的:服务器端返回的json数据格式如下: {"userbean":{"Uid":"100196","Showname&qu ...

  7. [Swift通天遁地]四、网络和线程-(11)将服务器返回的JSON映射为实例对象

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  8. $.ajax返回的JSON格式的数据后无法执行success的解决方法

    近段时间做项目,在项目使用了ajax技术,遇到了一个奇怪的问题:"$.ajax返回的JSON格式的数据无法执行success",代码是这样写的: 1 $.ajax({ 2 .. 3 ...

  9. 接口返回数据Json格式处理

    有这样一个页面 , 用来显示用户的账户记录数据,并且需要显示每个月的 收入 支出合计 ,在分页的时候涉及到一些问题,需要对返回的Json格式做处理,处理起来比较麻烦,后端返回的Json数据格式形式如下 ...

随机推荐

  1. 洛谷 P3808 【模板】AC自动机(简单版)洛谷 P3796 【模板】AC自动机(加强版)

    https://www.cnblogs.com/gtarcoder/p/4820560.html 每个节点的后缀指针fail指针指向: 例如he,she,his,hers的例子(见蓝书P214): 7 ...

  2. 修改SolrCloud在ZooKeeper中的配置文件操作记录

    修改SolrCloud在ZooKeeper中的配置文件操作记录. 命令执行目录: /opt/solr-/server/scripts/cloud-scripts/ 1.下载配置文件 ./zkcli., ...

  3. [转]WF事件驱动

    本文转自:http://www.cnblogs.com/Mayvar/archive/2011/09/03/wanghonghua_201109030446.html 已经有不少朋友知道Workflo ...

  4. AJPFX关于this用法和注意事项

    this:代表对象.就是所在函数所属对象的引用.哪个对象调用了this所在的函数,this就代表哪个对象,就是哪个对象的引用.开发时在定义功能时,如果该功能内部使用到了调用该功能的对象,这时就用thi ...

  5. Hibernate配置详解

    <!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> <?xml version='1.0' ...

  6. iOS捷径(Workflow 2.0)拓展

    前言 iOS12 捷径(Workflow 2.0)入门 iOS12 捷径(Workflow 2.0)进阶 iOS12捷径(Workflow 2.0)实例大全 注:本文主要介绍如何获取URL Schem ...

  7. (转)淘淘商城系列——KindEditor富文本编辑器的使用

    http://blog.csdn.net/yerenyuan_pku/article/details/72809794 通过上文的学习,我们知道了怎样解决KindEditor富文本编辑器上传图片时的浏 ...

  8. day21-4 菱形继承问题(类的查找顺序)

    目录 菱形继承问题 经典类(了解) 新式类 mro方法 菱形继承问题 在Python中子类可以同时继承多个父类,如A(B,C,D) 如果继承关系为非菱形结构,则会按照先找B这一条分支,然后再找C这条分 ...

  9. js 删除数组中某一项的几种方法总结

    第一种:改变原数组 借用原生数组方法:splice(index,len,[item])  剪接 借用原生对象方法:delete array[index] + array.slice(0, index) ...

  10. 关于 <script type='text/template' > 的妙用 / 使用jquery获取iframe加载完成事件

    https://www.cnblogs.com/ddqyc/p/6200539.html <!DOCTYPE html> <html> <head> <met ...