如何使用vb.net向Parse发送通知

如何使用vb.net向Parse发送通知,.net,json,vb.net,parse-platform,.net,Json,Vb.net,Parse Platform,当我尝试推送以下JSON数据时,它显示“远程服务器返回错误:(400)错误请求”。只有当JSON数据内容都在单引号中时,它才会成功 { 'mbs':{ 'msg':{ 'i':'6510', 'c':'0', 'st':'030116125200', 'et':'030116135800', 'rs':'0', 'mt':'1', '

当我尝试推送以下JSON数据时,它显示“远程服务器返回错误:(400)错误请求”。只有当JSON数据内容都在单引号中时,它才会成功

    {  
   'mbs':{  
      'msg':{  
         'i':'6510',
         'c':'0',
         'st':'030116125200',
         'et':'030116135800',
         'rs':'0',
         'mt':'1',
         'r':'165908',
         'ms':'256',
         's':'1',
         'tr':'2',
         'l':'en-US',
         'mr':'0',
         'th':'green',
         'dl':'1',
         'h':'1',
         'd':[  
            {  
               'data':'<p><span style="font-family: Calibri; font-size: 14px;">Enter the content of your alert below. Click on Save to save your changes. When ready to publish the alert, click on Publish.</span></p>'
            },
            {  
               'data':'<p><span style="font-family: Calibri; font-size: 14px;">Enter the content of your alert below. Click on Save to save your changes. When ready to publish the alert, click on Publish.</span></p>'
            }
         ],
         't':[  
            {  
               'data':'English'
            },
            {  
               'data':'English'
            }
         ]
      }
   }
}
{
'mbs':{
'msg':{
‘我’:‘6510’,
“c”:“0”,
‘st’:‘030116125200’,
‘et’:‘030116135800’,
“rs”:“0”,
‘mt’:‘1’,
‘r’:‘165908’,
'ms':'256',
's':'1',
‘tr’:‘2’,
‘l’:‘en-US’,
“mr”:“0”,
'th':'绿色',
‘dl’:‘1’,
‘h’:‘1’,
“d”:[
{  
“数据”:“在下面输入警报的内容。单击“保存”保存更改。准备发布警报时,单击“发布”。

” }, { “数据”:“在下面输入警报的内容。单击“保存”保存更改。准备发布警报时,单击“发布”。

” } ], ‘t’:[ { “数据”:“英语” }, { “数据”:“英语” } ] } } }
我使用了下面的vb.net代码

Private Function PushNotifications(ByVal PushMessage As String) As Boolean
    Dim isPushMessageSend As Boolean = False
    Dim postString As String = ""
    Dim urlpath As String = "https://api.parse.com/1/push"
    Dim httpWebRequest = DirectCast(WebRequest.Create(urlpath), HttpWebRequest)

    postString = "{ ""where"": {}, " & """data"" : {""alert"":""" & PushMessage & """}" & "}" 'for sending to everyone
    httpWebRequest.ContentType = "application/json"
    httpWebRequest.ContentLength = postString.Length
    httpWebRequest.Headers.Add("X-Parse-Application-Id", "*****")
    httpWebRequest.Headers.Add("X-Parse-REST-API-KEY", "*****")
    httpWebRequest.Method = "POST"
    Dim requestWriter As New StreamWriter(httpWebRequest.GetRequestStream())
    requestWriter.Write(postString)
    requestWriter.Close()
    Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
    Using streamReader = New StreamReader(httpResponse.GetResponseStream())
        Dim responseText = streamReader.ReadToEnd()

        Dim jobjRes As JObject = JObject.Parse(responseText)
        If Convert.ToString(jobjRes).IndexOf("true") <> -1 Then
            isPushMessageSend = True
        End If
        System.IO.File.WriteAllText("D:\jsondata4.txt", jobjRes.ToString())
    End Using
    MessageBox.Show("Successfully sent")
    Return isPushMessageSend
End Function
私有函数PushNotifications(ByVal PushMessage作为字符串)作为布尔值
Dim isPushMessageSend As Boolean=False
Dim postString As String=“”
Dim urlpath作为字符串=”https://api.parse.com/1/push"
Dim httpWebRequest=DirectCast(WebRequest.Create(urlpath),httpWebRequest)
postString=“{”where”“:{},&”“data”“:{”“alert”“:”“&PushMessage&”“}”&用于发送给所有人
httpWebRequest.ContentType=“应用程序/json”
httpWebRequest.ContentLength=postString.Length
httpWebRequest.Headers.Add(“X-Parse-Application-Id”,“****”)
httpWebRequest.Headers.Add(“X-Parse-REST-API-KEY”,“*****”)
httpWebRequest.Method=“POST”
Dim requestWriter作为新的StreamWriter(httpWebRequest.GetRequestStream())
requestWriter.Write(postString)
requestWriter.Close()
Dim httpResponse=DirectCast(httpWebRequest.GetResponse(),HttpWebResponse)
使用streamReader=newstreamreader(httpResponse.GetResponseStream())
Dim responseText=streamReader.ReadToEnd()
Dim jobjRes As JObject=JObject.Parse(responseText)
如果Convert.ToString(jobjRes.IndexOf(“true”)-1,则
isPushMessageSend=True
如果结束
System.IO.File.WriteAllText(“D:\jsondata4.txt”,jobjRes.ToString())
终端使用
MessageBox.Show(“已成功发送”)
返回isPushMessageSend
端函数

这是因为您的值包含双引号。 这项工作:

“数据”:“”

这不会:

“数据”:“”

因为它被解析为
“数据”:“”
不是有效的JSON