我如何创建这个Json [英] How Do I Create This Json

查看:114
本文介绍了我如何创建这个Json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如何创建:



{data:[{ 诺卜醇: B1106PFB},{ 诺卜醇: B1120UOK},{ 诺卜醇: B6082PPR},{ 诺卜醇: B6354PDW},{ 诺卜醇: B777},{ nopol:BG8882KP}]}



在asp.net上使用json_encode(vb)



谢谢

解决方案

创建一个镜像你的Json数据的类。

< datacontract> _ 
公开 基准
< datamember> _
公开 属性 nopol As 字符串
结束

< datacontract> _
公开 CP
< datamember> _
公开 属性数据 As 基准()
结束





用数据加载对象。

  Dim  oDatum < span class =code-keyword> As   Datum()使用 {.nopol =  测试值} 
Dim oData 作为 CP()使用 {.data = {oDatum}}





然后调用Json Serializer

 使用 oMemStream 作为  IO.MemoryStream()
Dim oJsonSerializer As Json.DataContractJsonSerializer(< span class =code-keyword> GetType (oData))
oJsonSerializer.WriteObject(oMemStream,oData)
Dim szJsonString As String = System.Text.Encoding.ASCII.GetString(oMemStream.ToArray())
结束 使用


hi所有,



搜索并尝试了解我理解的最佳方法

最后我决定使用newton json



这里是:



进口Newtonsoft.Json

进口Newtonsoft.Json.Linq


Dim counter As Integer = 0

Dim jsonstr As String = Request.Form(field1)。ToString

昏暗的r作为JObject = JObject.Parse(jsonstr)

Dim data1作为List(Of JToken)= ser.Children()。ToList

Dim output As String =

Dim field As String =(

Dim valstr As String =



每个项目为JProperty In data1

item.CreateReader()

For Each comment As JObject in item.Values

Dim u As String

Dim d As String = comment(fuel)

Dim c As String = comment(nopolisi)

Dim su As String = comment(surveyId )

Dim km As String = comment(km)

Dim kondisi As String = comment(kondisi)

Dim keterangan As String = comment(keterangan)

nopol = c

如果评论(image_data)。Count = 0那么

u =评论(image_data)

输出+ =('+ + +','+ d +','+ c +','+ su +' ,'+ km +','+ kondisi +','+ keterangan +'),

Else

For i = 0发表评论(image_data)。计数 - 1

u =评论(image_data)(i)

输出+ =('+ u +',' + d +','+ c +','+ su +','+ km +','+ kondisi +','+ keterangan +'),

下一页

结束如果

下一页

下一页



就是这样。



希望它可以帮助其他人,他们面临像我这样的问题:)



谢谢

hi all,

how do i create :

{"data":[{"nopol":"B1106PFB"},{"nopol":"B1120UOK"},{"nopol":"B6082PPR"},{"nopol":"B6354PDW"},{"nopol":"B777"},{"nopol":"BG8882KP"}]}

using json_encode on asp.net (vb)

thanks

解决方案

Create a class the mirrors your Json data.

<datacontract> _
Public Class Datum
     <datamember> _
     Public Property nopol As String
End Class

<datacontract> _
Public Class CP
     <datamember> _
     Public Property data As Datum()
End Class



Load the objects with data.

Dim oDatum As New Datum() With {.nopol = "Test Values"}
Dim oData As New CP() With {.data = {oDatum}}



Then call the Json Serializer

Using oMemStream As New IO.MemoryStream()
    Dim oJsonSerializer As New Json.DataContractJsonSerializer(GetType(oData))
    oJsonSerializer.WriteObject(oMemStream, oData)
    Dim szJsonString As String = System.Text.Encoding.ASCII.GetString(oMemStream.ToArray())
End Using


hi all,

after searching and trying with the best method that i understand
finally i decided using newton json

here it is :

Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq

Dim counter As Integer = 0
Dim jsonstr As String = Request.Form("field1").ToString
Dim ser As JObject = JObject.Parse(jsonstr)
Dim data1 As List(Of JToken) = ser.Children().ToList
Dim output As String = ""
Dim field As String = "("
Dim valstr As String = ""

For Each item As JProperty In data1
item.CreateReader()
For Each comment As JObject In item.Values
Dim u As String
Dim d As String = comment("fuel")
Dim c As String = comment("nopolisi")
Dim su As String = comment("surveyId")
Dim km As String = comment("km")
Dim kondisi As String = comment("kondisi")
Dim keterangan As String = comment("keterangan")
nopol = c
If comment("image_data").Count = 0 Then
u = comment("image_data")
output += "('" + u + "','" + d + "','" + c + "','" + su + "','" + km + "','" + kondisi + "','" + keterangan + "'),"
Else
For i = 0 To comment("image_data").Count - 1
u = comment("image_data")(i)
output += "('" + u + "','" + d + "','" + c + "','" + su + "','" + km + "','" + kondisi + "','" + keterangan + "'),"
Next
End If
Next
Next

that's it.

hope it can helps others, who's facing problems like me :)

thanks


这篇关于我如何创建这个Json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆