服务器返回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. DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

    题目传送门 /* DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : */ #include <cstdio> #include <iostream&g ...

  2. 题解报告:hdu 2058 The sum problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2058 问题描述 给定一个序列1,2,3,...... N,你的工作是计算所有可能的子序列,其子序列的总 ...

  3. Object C学习笔记18-SEL,@ selector,Class,@class--转

    一. SEL 类型 在上一篇介绍了几个方法,都只是介绍了其使用方式但是没有具体介绍参数: - (id)performSelector:(SEL)aSelector; - (id)performSele ...

  4. [转]无废话SharePoint入门教程二[SharePoint发展、工具及术语]

    本文转自:http://www.cnblogs.com/iamlilinfeng/p/3186919.html 一.前言 1.由于上一篇文章的标题命名失误,此篇标题写给百度搜索”什么是SharePoi ...

  5. 关于C# DropDownList 动态加载数据笔记

    今天在处理一个导游注册的页面,其中需要填写地址以及该地址下所有旅行社,地址区级以上都是用下拉列表实现,具体地址街道等手动填写.在填写区县之后,该区县下的所有旅行社也需要动态加载. 后台代码 DataT ...

  6. 请大家帮我找一找bug —— 一个MySQL解析程序(JAVA实现)

    周末两天我写了一个MySQLParser.写这个东西的目的是:公司的一个项目中需要对数据打版本号(每个表的每条记录要有一个版本号字段,这个字段需要由框架自动打上去,而不是由程序员来做). 所以,我写的 ...

  7. [备忘]Notification的实用

    Intent resultIntent = null; if (!TextUtils.isEmpty(tid)){ resultIntent = new Intent("com.shijie ...

  8. 让TortoiseGit记住帐号密码方法

    我的电脑环境是: Windows7 64x   系统用户名是:steden 所以,我的路径是:C:\Users\steden\ 具体要根据你的系统环境及当前用户名来决定. 在这里,有个文件:.gitc ...

  9. hibernate4+spring4+struts2的Maven中的pom.xml文件的配置

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  10. 迅为IMX6UL开发板

    迅为iMX6UL开发板采用核心板加底板形式,核心板使用邮票孔方式连接,牢固耐用.处理器ARM®Cortex®-A7内核,运行速度高达528 MHz.512MDDR内存,8G EMMC存储,板截双网口, ...