“从JsonReader读取JObject时出错。路径位置0” VB.net

时间:2019-10-31 20:46:26

标签: json vb.net web-services

因此,我正在制作一个通过HTTP发送此Json的Android应用

{"InfoCustomer":[{"AWB":"SHP#.39535","NUMBOXES":"2","FB":"0.5","CUBIC":"3.14","ORIGIN":"QUITO","ACCEPT":"1","REJECT":"","SHIPTO":"GG MIAMI"}]}

我的vb控制器如下所示:

<Route("image/Upload2")>
    <AllowAnonymous>
    <HttpPost>
    Public Async Function Upload2() As Task(Of HttpResponseMessage)
        Try
            Dim StringJSON As String = ""
            Dim httpRequest = HttpContext.Current.Request
            If httpRequest.Files.Count > 0 Then

                For Each file As String In httpRequest.Files
                    Dim postedFile = httpRequest.Files(file)
                    Dim fileName = postedFile.FileName


                    If file.Equals("INFOJSON") Then
                        StringJSON = System.Web.HttpUtility.UrlDecode(postedFile.ToString)
                        GuardarEnArchivo("StringJSON:" & StringJSON)
                    End If
                Next
            End If

            Dim objCrd As CargoplusService = New CargoplusService()
            Dim IdSignatureHeader As String = ""

            IdSignatureHeader = objCrd.funInsSignatureShippingDetailPOD2(StringJSON)

            '        'Return New HttpResponseMessage()
            Return Request.CreateResponse(Of String)(IdSignatureHeader)
        Catch ex As Exception
            GuardarEnArchivo(ex.ToString)
            Return New HttpResponseMessage()
        End Try
    End Function

我的函数如下:

 Public Function funInsSignatureShippingDetailPOD2(ByVal pStringJSON As String) As String
        Try
            Dim strSQL As String                                      'String donde se almacena el nombre del SP
            Dim objConn As dbConnector = New dbConnector()            'Coneccion para la base de datos
            Dim dsData As New DataSet
            Dim json As JObject = JObject.Parse(pStringJSON)
            Dim data As List(Of JToken) = json.Children().ToList      ''deserializa el json
            Dim IdSignatureHeader As Integer = 88                     'inicializa valores con -1
            Dim InsWhenUpd As Integer = 99
            Dim NewSignature As String = "0"                           'Declaracion de de un string vacio  
            For Each item As JProperty In data                        'itera cada item
                item.CreateReader()
                Select Case item.Name
                    Case "InfoCustomer"
                        For Each msg As JObject In item.Values
                            'GuardarEnArchivo(msg.ToString())
                            Dim IdShippingDetail As String = msg("IdShippingDetail").ToString
                            Dim Boxes As String = msg("Boxes").ToString
                            Dim Aceptado As String = msg("Aceptado").ToString
                            NewSignature = msg("NewSignature").ToString
                            Dim IdRelCompanyType As String = msg("IdRelCompanyType").ToString
                            Dim ShippingDate As String = msg("ShippingDate").ToString
                            Dim ActiveSignature As String = msg("ActiveSignature").ToString
                            Dim AWB As String = msg("AWB").ToString
                            Dim FB As String = msg("FB").ToString
                            Dim Cubic As String = msg("Cubic").ToString
                            Dim Origin As String = msg("Origin").ToString
                            Dim ShipToName As String = msg("ShipToName").ToString

                            'If NewSignature.Equals("0") Then 'Crear nuevos registros en la tabla CM_SHIPPING_DETAIL_POD
                            ' GuardarEnArchivo("CREAR NUEVA FIRMA")
                            strSQL = "usp_InsSignatureShippingDetailPOD"
                            dsData = objConn.executeSQLDataset(strSQL, {{"@IdSignatureHeader", IdSignatureHeader},
                                                                    {"@SignatureDate", Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"))},
                                                                    {"@SignaturePath", "pPathImage"},
                                                                    {"@SignatureComments", ""},
                                                                    {"@IdShippingDetailPOD", "-1"},
                                                                    {"@IdShippingDetail", IdShippingDetail},
                                                                    {"@Boxes", Boxes},
                                                                    {"@ShippingAccepted", Aceptado},
                                                                    {"@InsOrUpd", NewSignature},
                                                                    {"@IdRelCompanyType", IdRelCompanyType},
                                                                    {"@ShippingDate", ShippingDate},
                                                                    {"@Active", ActiveSignature},
                                                                    {"@AWB", AWB},
                                                                    {"@FB", FB},
                                                                    {"@Cubic", Cubic},
                                                                    {"@Origin", Origin},
                                                                    {"@InsWhenUpd", InsWhenUpd},
                                                                    {"@ShipToName", ShipToName}
                                                                    })

                            IdSignatureHeader = dsData.Tables(0).Rows(0).Item("IdSignatureHeader")
                            'End If
                        Next
                End Select
            Next

            If NewSignature.Equals("0") Then
                Return "Executed"
            Else
                Return "Not Executed"
            End If
        Catch ex As Exception
            GuardarEnArchivo(ex.ToString)
            Return ex.Message + pStringJSON + "asi es"
        End Try
    End Function

作为一个新的Web服务开发人员,我不知道如何正确调试Web服务,我只能通过在线api测试器对服务进行测试,ehich返回此错误消息:从JsonReader读取JObject时出错。路径”,第0行,位置0,请帮助

0 个答案:

没有答案