2013-10-17 74 views
0

我想从一个http文章阅读json字符串,我试图通过手动填充json字符串来测试我的代码,但我的问题是我无法添加相同的节点多次....换句话说,如果我把下面的工作原理:错误阅读json字符串

Dim json As String = "{'name': 'jocelyne','mo': '70274724'} 

,但如果我把下面的这是行不通的:

Dim json As String = "{'name': 'jocelyne','mo': '70274724'},{'name': 'eliane','mo': '12345678'}" 

,我实际上是名称的一百莫数字将发送给我一个json字符串

这是我的全部代码:

Request.InputStream.Position = 0 'you need this else the magic doesn't happen 
    Dim inputStream As New StreamReader(Request.InputStream) 
    'Dim json As String = inputStream.ReadToEnd() 
    Dim json As String = "{'name': 'jocelyne','mo': '70274724'},{'name': 'eliane','mo': '12345678'}" 

    Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer() 
    Dim dict As Dictionary(Of String, String) = jss.Deserialize(Of Dictionary(Of String, String))(json) 

    For Each item As KeyValuePair(Of String, String) In dict 
     Response.Write(item.Key & " - " & item.Value & "<br>") 
    Next 

怎么能解决这个问题?我只是需要能够读取使用HTTP POST给我这个JSON格式和反序列化读取数据

+0

如果我传递数组,我需要传递JSON字符串 – Vandesh

+0

@Vandesh中的 - “[{}],[{}]”这样的JSON对象数组:'无效的JSON基元:[{'name ':'eliane','mo':'12345678'}]。'当初始化字典时 – User7291

回答

0

有必要把整串,以括号

Dim serializer As New Web.Script.Serialization.JavaScriptSerializer() 
Dim json As String = "[{'name': 'jocelyne','mo': '70274724'},{'name': 'eliane','mo': '12345678'}]" 
Dim tst = serializer.Deserialize(Of Object)(json) 

结果是对象数组。