2
testdata =
"{payments:
  [{'status': 'succeeded', 
    'in_store_payment_type': None, 
    'refunds': [], 
    'created_at': '2021-10-20T17:23:41-0400', 
    'amount_paid_display': '53.00', 
    'initial_amount_paid_display': '53.00', 
    'currency': 'usd', 
    'initial_amount_paid': 5300, 
    'pk': 75552720, 
    'type': 'affiliate', 
    'amount_paid': 5300
  }]
}"

I have tried:

<%@ LANGUAGE="VBSCRIPT" %>  
<!--#include file="aspJSON.asp" -->
<%
(read testdata....)

set oJSON= json.parse(testdata)

response.write "Data->" & oJSON.payments.get(0).status
%>

Had hoped to see "succeeded" but no luck.
any suggestions?

user692942
  • 16,398
  • 7
  • 76
  • 175
GaryG
  • 21
  • 3
  • Does this answer your question? [How to access JSON data in classic ASP using json2.asp or aspjson libraries?](https://stackoverflow.com/q/24974362) (seen as though you've deleted the [other question](https://stackoverflow.com/questions/69981270/get-data-from-a-json-array-using-classic-asp-i-have-json2-asp-and-or-aspjson-a)). – user692942 Nov 18 '21 at 20:51
  • Well, I think it does BUT, I could not get it to work with my data – GaryG Nov 18 '21 at 20:58
  • The sample you've provided doesn't look like the correct syntax for Classic ASP, the `#include` isn't structured properly and the VBScript should be contained within `<% ... %>` ASP preprocessor tags. This would never run, you must be getting an error could you actually [edit] the question and post what the error is or a runnable sample at least? – user692942 Nov 18 '21 at 21:03
  • 1
    That data you've provided isn't JSON. You'll have to parse it manually. – miken32 Nov 18 '21 at 21:33
  • Single quotes (`'`) for identifiers is not valid in a JSON object, you should use double quotes (`"`). See [Introducing JSON](https://www.json.org/json-en.html) – user692942 Nov 18 '21 at 21:54

1 Answers1

0

A couple of issues with this script, not a fan of the aspJSON library personally but this should get you started (change the #include location to suit your environment).

<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<!-- #include virtual = "/scripts/aspJSON1.19.asp" -->
<%
Dim testdata: testdata = _
  "{""payments"" :" & _
  "  [{""status"": ""succeeded""," & _
  "   ""in_store_payment_type"": None," & _ 
  "   ""refunds"": []," & _
  "   ""created_at"": ""2021-10-20T17:23:41-0400""," & _
  "   ""amount_paid_display"": ""53.00""," & _
  "   ""initial_amount_paid_display"": ""53.00""," & _
  "   ""currency"": ""usd""," & _
  "   ""initial_amount_paid"": 5300," & _
  "   ""pk"": 75552720," & _
  "   ""type"": ""affiliate""," & _
  "   ""amount_paid"": 5300" & _
  " }]" & _
  "}"

Dim oJSON: Set oJSON = New aspJSON
Call oJSON.loadJSON(testdata)
Dim payment
For Each payment In oJSON.data("payments")
  Dim this: Set this = oJSON.data("payments")(payment)
  response.write "Data->" & this.item("status")
Next
%>

Output:

Data->succeeded

A couple of key points

  • JSON needs to use double quotes (") not single quotes (') for it's identifiers. Ref Introducing JSON
  • The aspJSON library does not support the parse() method, instead you use loadJSON().
  • You need to enumerate the payments collection using a For statement to access properties inside the enumerated object.

Useful Links

user692942
  • 16,398
  • 7
  • 76
  • 175