SleepsOnNewspapers
SleepsOnNewspapers

Reputation: 3373

Parse through JSON in Parse.com Cloud Code and Stripe

I'm trying to parse through the DOM object you can find via this link, which shows the JSON response when accessing the Stripe API. I'm doing this with the Parse.com Cloud Code SDK which prevents the use of jQuery. Does anyone know how to do this? Specifically I'm trying to access the subscription object of the customer to see if a subscription is 'active'. Thanks

Upvotes: 0

Views: 969

Answers (1)

Sam
Sam

Reputation: 320

Assuming you get your response through Parse.Cloud.httpRequest

Parse.Cloud.httpRequest(
{
    url: 'yourUrlRequest.com'
    success: function(httpResponse) 
    {
        var jsonResponse = JSON.parse(httpResponse.text);
        var subsObject = jsonResponse.subscriptions;
        // access subsObject.object, subsObject.total_count, subsObject.has_more, subsObject.url etc.
        // ...
    },
    error: function(httpResponse) 
    {
        response('Request failed with response code ' + httpResponse.status)
    }
});

If you are getting the API response some other way, just JSONify it ands then access the fields through dot notation (in the same way as above).

Upvotes: 2

Related Questions