我正在尝试将一个API集成到我的项目中,该API返回JSON字符串。请检查以下示例JSON字符串。
{
"records":{
"Plan":[
{
"rs":{
"**3 MONTHS**":"1611",
"6 MONTHS":"2971",
"1 YEAR":"5399"
},
"desc":"12 month SD pack + Rs 600 only",
"plan_name":"Infinity",
"last_update":"14-08-2018"
},
{
"rs":{
"1 MONTHS":"165",
"3 MONTHS":"499",
"6 MONTHS":"994",
"1 YEAR":"1819"
},
"desc":"11M +1M Free",
"plan_name":"South My Plan 99",
"last_update":"14-08-2018"
},
{
"rs":{
"1 MONTHS":"219",
"3 MONTHS":"656",
"6 MONTHS":"1313",
"1 YEAR":"2408"
},
"desc":"11M + 1M Free",
"plan_name":"Freedom Entertainment",
"last_update":"01-01-1970"
}
]
},
"status":1
}
现在,我正在尝试使用以下方法在数据集中转换上述字符串。
Public Function GetJsonArrayToDataSet(ByVal sJsonData As String) As DataSet
Dim dSetJson As New DataSet
Dim xDoc As New XmlDocument
Dim sJsonXML As String = String.Empty
Try
sJsonData = Replace(sJsonData, "'", "")
sJsonData = "{""rootNode"": " & sJsonData & " }"
xDoc = JsonConvert.DeserializeXmlNode(sJsonData, "rootNode")
If xDoc IsNot Nothing Then
sJsonXML = xDoc.OuterXml
dSetJson.ReadXml(New StringReader(sJsonXML))
Return dSetJson
Else
Return Nothing
End If
Catch ex As Exception
Return Nothing
End Try
End Function
在这里出现如下错误
The ' ' character, hexadecimal value 0x20, cannot be included in a name.***
因为空格在关键部分中。我还尝试手动从键中删除空间,然后再次检查,但出现如下错误:
Name cannot begin with the '3' character, hexadecimal value 0x33. Line 1, position 41.
请告诉我上述问题的解决方法。