将vb.net数据转换为json字符串并将其发送到特定URL

发布于 2024-11-05 01:01:38 字数 757 浏览 0 评论 0原文

这是使用给定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人的旅程 2024-11-12 01:01:39

创建一个属性名称与示例中的属性名称相同的对象,使用 DataContractDataMember 属性来标记序列化。

然后使用 JavaScriptSerializer 将对象序列化为 JSON。

当您想要在托管代码中使用 JavaScript 对象表示法 (JSON) 时,可以使用该类。

Create an object with property names that are identical to those in your example, use the DataContract and DataMember attributes to mark serialization.

Then use the JavaScriptSerializer to serialize the object into JSON.

you can use the class when you want to work with JavaScript Object Notation (JSON) in managed code.

秋千易 2024-11-12 01:01:39

如果您不想按照 @Oded 的建议构建实际的类,您可以将其作为字符串组合在一起。我通常使用 NameValueCollection 正如你所说的你尝试过的。

    ''//Setup some values
    Dim NVC As New NameValueCollection()
    NVC.Add("id", "5")
    NVC.Add("owner_id", "0")
    NVC.Add("status", "unassigned")

    ''//Convert to string
    Dim Pairs As New List(Of String)
    For Each N As String In NVC.Keys
        Pairs.Add(String.Format("""{0}"":""{1}""", N.Replace("""", "\"""), NVC(N).Replace("""", "\""")))
    Next
    Dim S = Join(Pairs.ToArray(), ",")

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.

    ''//Setup some values
    Dim NVC As New NameValueCollection()
    NVC.Add("id", "5")
    NVC.Add("owner_id", "0")
    NVC.Add("status", "unassigned")

    ''//Convert to string
    Dim Pairs As New List(Of String)
    For Each N As String In NVC.Keys
        Pairs.Add(String.Format("""{0}"":""{1}""", N.Replace("""", "\"""), NVC(N).Replace("""", "\""")))
    Next
    Dim S = Join(Pairs.ToArray(), ",")

S now holds "id":"5","owner_id":"0","status":"unassigned" which you should be able to concat into your bigger JSON string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文