将 JSON 字符串转换为 JSON 对象 c# [英] Convert JSON String to JSON Object c#

查看:44
本文介绍了将 JSON 字符串转换为 JSON 对象 c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将此字符串存储在我的数据库中:

I have this String stored in my database:

str = "{ "context_name": { "lower_bound": "value", "upper_bound": "value", "values": [ "value1", "valueN" ] } }"

此字符串已经是 JSON 格式,但我想将其转换为 JObject 或 JSON 对象.

This string is already in the JSON format but I want to convert it into a JObject or JSON Object.

JObject json = new JObject();

我尝试了 json = (JObject)str; 强制转换,但它不起作用,我该怎么做?

I tried the json = (JObject)str; cast but it didn't work so how can I do it?

推荐答案

JObject 为此定义了方法 Parse:

JObject json = JObject.Parse(str);

您可能需要参考 Json.NET 文档.

You might want to refer to Json.NET documentation.

这篇关于将 JSON 字符串转换为 JSON 对象 c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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