【发布时间】:2020-09-28 22:57:20
【问题描述】:
我正在从我的 WebMethod 接收此 JSON:
{
"TableName": "myTable",
"Table": [
{
"ProdOrder": "245392",
"Item": "C01000FLS0300GF",
"Qty": 40
},
{
"ProdOrder": "245393",
"Item": "C01000FLS0400GF",
"Qty": 20
}
]
}
这是网络方法:
<WebMethod()>
Public Function MyWebMethod(strJSON As String) As String
Dim objJSON As Object = New JavaScriptSerializer().Deserialize(Of Object)(strJSON)
'Get TableName
Dim strTableName As String = objJSON("TableName")
'Get Data
Dim arrJSON As Object() = objJSON("Table")
For i As Integer = 0 To arrJSON.Length - 1
Dim ProdOrder As String = arrJSON(i)("ProdOrder")
Dim Item As String = arrJSON(i)("Item")
Dim Qty As String = arrJSON(i)("Qty")
Next
Return "OK"
End Function
直到这里一切都非常简单并且可以工作。
我现在的问题是,如果我不知道字段的名称,如何获取它们?
我的意思是,任何获取“ProdOrder”、“Item”和“Qty”的方式......
使用 arrJSON(i)("ProdOrder") 我得到了价值。如何获得标题“ProdOrder”?
【问题讨论】: