Call a Web Service

#This script calls a webservice that parses and populates a Spotfire Document property from the returned JSON format.
import clr
clr.AddReference('System.Web.Extensions') from System.Net import WebClient from System.Collections.Generic import Dictionary from System.IO import StreamReader from System.Web.Script.Serialization import JavaScriptSerializer # get the json data url = '' wc = WebClient() wc.Headers.Add('Content-Type', 'application/x-www-form-urlencoded') requestData= wc.OpenRead(url) reader = StreamReader (requestData); response = reader.ReadToEnd() #Parse the results js = JavaScriptSerializer() responseDict = js.Deserialize(response,object) item1 = responseDict["RestResponse"]["result"]["name"] item2 = responseDict["RestResponse"]["result"]["alpha2_code"] print item1,item2 #result is Mexico MX


mahesh said...

HI am new this technology help me here.

Hi I tried to run above code i am getting error
"Traceback (most recent call last):
File "Spotfire.Dxp.Application.ScriptSupport", line unknown, in ExecuteForDebugging
File "", line 4, in
ImportError: No module named Script"

Do i need to install any thing here?

Jose Leviaguirre said...


SystemWeb.Script requires System.Web.Extensions:

import clr

Sorry about that.