以下是使用Json.NET的JSON输出。为什么所有的" \"被插入?
输出
{\"titles\":[{\"lesson\":1.0,\"title\":\"Objectives\"},{\"lesson\":2.0,\"title\":\"What are Cars?\"},{\"lesson\":3.0,\"title\":\"The Role of Cars\"}],\"objective\":[{\"objective\":\"Describe cars.\"},{\"objective\":\"Describe the role of cars.\"},{\"objective\":\"Define cars.\"}]}
代码
Dim dst As DataSet = db.ExecuteDataSet(dbCommand)
Dim sb As New StringBuilder()
Dim sw As New StringWriter(sb)
Dim writer As JsonWriter = New JsonTextWriter(sw)
writer.WriteStartObject()
If dst.Tables(1).Rows.Count > 0 Then
writer.WritePropertyName("titles")
writer.WriteStartArray()
For i As Integer = 0 To 2
writer.WriteStartObject()
writer.WritePropertyName("lesson")
writer.WriteValue(dst.Tables(1).Rows(i).Item("lesson"))
writer.WritePropertyName("title")
writer.WriteValue(dst.Tables(1).Rows(i).Item("title").ToString)
writer.WriteEndObject()
Next
writer.WriteEndArray()
End If
If dst.Tables(2).Rows.Count > 0 Then
writer.WritePropertyName("objective")
writer.WriteStartArray()
For i As Integer = 0 To 2
writer.WriteStartObject()
writer.WritePropertyName("objective")
writer.WriteValue(dst.Tables(2).Rows(i).Item("objective"))
writer.WriteEndObject()
Next
writer.WriteEndArray()
End If
writer.WriteEndObject()
答案 0 :(得分:0)
你得到所有“\”字符的原因是因为你只有一个字符串。该字符串需要像这样解析
JObject root = JObject.Parse('your_string_here');
我希望这会对你有所帮助。