views:

272

answers:

1

Can someone convert below code to ASP format?

<?php

$data = '
[
  {
    "A": "test",
    "B": "test",
    "C": "test"
  },
  {
    "A": "test",
    "B": "test",
    "C": "test"
  }
]
';

print($_GET['callback'] .'('. $data .')');

while I was testing cross domain restriction workaround, this code works fine with PHP server (of course) , thing is I'd like to implement this under ASP environment. I tried here http://www.me-u.com/php-asp/hosting/asp.php though. Thanks in advance.

+2  A: 

Like, once?

<%
Dim data 

''// VBScript Strings cannot span multiple lines, we must use
''// concatenation ("&") and line continuation markers ("_")
''// (also, double quotes need to be escaped by *double* double quotes)
data = "" & _
  "[" & _
  "  {" & _
  "    ""A"": ""test""," & vbCrLf & _
  "    ""B"": ""test""," & vbCrLf & _
  "    ""C"": ""test"""  & vbCrLf & _
  "  }," & vbCrLf & _
  "  {" & vbCrLf & _
  "    ""A"": ""test""," & vbCrLf & _
  "    ""B"": ""test""," & vbCrLf & _
  "    ""C"": ""test""" & vbCrLf & _
  "  }" & vbCrLf & _
  "]"

Response.Write Request.QueryString("callback") & "(" & data & ")"
%>

The whole string concatenation business can be avoided if you are going to print out all of it anyway (e.g. there is no further use for it being in a variable):

<%
Response.Write Request.QueryString("callback") & "("
%>
[
  {
    "A": "test",
    "B": "test",
    "C": "test"
  },
  {
    "A": "test",
    "B": "test",
    "C": "test"
  }
]
<%
Response.Write ")"
%>
Tomalak
Thanks for your quick answer, let me work on it.
jmoon
WOW, nice, 2nd one working, Thank you so much.
jmoon
Thanks again. you really made my day.
jmoon