将vb.net数据转换为json字符串并将其发送到特定URL
这是使用给定 URL 发送数据所需的 JSON 字符串。
$jsonstr = '{"data":
[{
"id":"5",
"owner_id":"0",
"status":"unassigned",
"first_name":"Test",
"last_name":"IS",
"tobacco_user":"",
"date_of_birth":"",
"age":"",
"gender":"",
"email":"[email protected]",
"zip":"",
"phone":"(210)629-2560",
"phone_type":"cell",
"phone_alt":"",
"phone_alt_type":"",
"product_msip":"",
"product_pdp":"",
"product_sdhv":""
},
我正在使用 VB.net,我需要使用 VB.net 创建这个字符串。我尝试使用 namevaluecollection 并执行 POST。我还尝试创建一个字符串并使用 GET 发送数据。两者都失败了。我该怎么做?
this is the JSON string the data is required in to be sent using a given URL.
$jsonstr = '{"data":
[{
"id":"5",
"owner_id":"0",
"status":"unassigned",
"first_name":"Test",
"last_name":"IS",
"tobacco_user":"",
"date_of_birth":"",
"age":"",
"gender":"",
"email":"[email protected]",
"zip":"",
"phone":"(210)629-2560",
"phone_type":"cell",
"phone_alt":"",
"phone_alt_type":"",
"product_msip":"",
"product_pdp":"",
"product_sdhv":""
},
I am using VB.net and i need to create this string using VB.net. I tried using namevaluecollection and doing a POST. I also tried making a string and send data using GET. Both failed. how can i do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个属性名称与示例中的属性名称相同的对象,使用
DataContract
和DataMember
属性来标记序列化。然后使用
JavaScriptSerializer
将对象序列化为 JSON。Create an object with property names that are identical to those in your example, use the
DataContract
andDataMember
attributes to mark serialization.Then use the
JavaScriptSerializer
to serialize the object into JSON.如果您不想按照 @Oded 的建议构建实际的类,您可以将其作为字符串组合在一起。我通常使用 NameValueCollection 正如你所说的你尝试过的。
S
现在拥有"id":"5","owner_id":"0","status":"unassigned"
您应该能够将其连接到更大的JSON 字符串。If you don't want to build an actual class as @Oded recommended you can just hack it together as a string. I usually use a NameValueCollection as you said you tried.
S
now holds"id":"5","owner_id":"0","status":"unassigned"
which you should be able to concat into your bigger JSON string.