在Parse.com Cloud Code和Stripe中通过JSON解析

时间:2022-08-13 15:50:13

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

我正在尝试通过此链接解析您可以找到的DOM对象,该链接显示访问Stripe API时的JSON响应。我正在使用Parse.com Cloud Code SDK来防止使用jQuery。有谁知道如何做到这一点?具体来说,我正在尝试访问客户的订阅对象,以查看订阅是否“有效”。谢谢

1 个解决方案

#1


2  

Assuming you get your response through Parse.Cloud.httpRequest

假设您通过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).

如果你以其他方式获得API响应,只需JSONify它然后通过点表示法访问字段(以与上面相同的方式)。

#1


2  

Assuming you get your response through Parse.Cloud.httpRequest

假设您通过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).

如果你以其他方式获得API响应,只需JSONify它然后通过点表示法访问字段(以与上面相同的方式)。