-1

I have a jQuery Ajax function that calls a WCF Service. The service call succeeds:

    function WCFJSON() {
        var now = new Date();
        var getFromDate = dateToWcf(new Date(now - (60000 * 1440)));

        var userid = "1";
        m_Type = "POST";
        m_Url = "https://dev-04.boldgroup.int/ManitouDashboard/DashboardProxyService.svc/GetStats"
        m_Data = '{"getFromDate": "' + getFromDate + '", "getValueList": [1, 2, 3, 7]}';
        m_DataType = "json";
        m_ProcessData = true;
        CallService();
    }  



    function CallService() {
    $.ajax({
        type: m_Type,           //GET or POST or PUT or DELETE verb                  
        url: m_Url,                 //Location of the service   
        data: m_Data,
        dataType: m_DataType,   //Expected data format from server                  
        processdata: m_ProcessData, //True or False
        crossdomain: true,    
        contentType: "application/json",             
        success: function (msg) {   //On Successfull service call                      
            ServiceSucceeded(msg);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            ServiceFailed("jqXHT: " + jqXHR.result + "Text Status: " + textStatus + " Error Thrown: " + errorThrown );
        } // When Service call fails              
    });
}

and I can see the raw json response string is populated using fiddler, how do I extract the values returned in the json response? I would like do get the values store them in a list or an array in javascript. Thanks for any advice on this.

Tim Post
  • 33,371
  • 15
  • 110
  • 174
CodeMan5000
  • 1,067
  • 2
  • 12
  • 21
  • What does the returned JSON look like? – Ry- Aug 31 '12 at 14:55
  • {"GetStatsResult":[{"Key":2,"Value":[{"StatDateTime":"\/Date(1346448742000-0600)\/","Value":"0"},{"StatDateTime":"\/Date(1346448747000-0600)\/","Value":"0"} – CodeMan5000 Aug 31 '12 at 16:15

2 Answers2

1

you can just use something like JSON2 to convert your response to a JSON Array object then you would just call it like any other array objects
your response would be like this

"[{\"name\":\"Qpirate\"},{\"name\":\"Qpirate\"}]"

and using JSON2 file

var returnedMsg = JSON.parse(msg);
Qpirate
  • 2,078
  • 1
  • 29
  • 41
1

The question below gives a good example of how to acess the properties.

Using variable keys to access values in JavaScript objects

Community
  • 1
  • 1
Gent
  • 2,675
  • 1
  • 24
  • 34