我有以下对象:
public class TestModel
{
public object TestValue { get; set; }
}
我的数据库包含 JSON 格式的字符串,例如
string dbValue1 = "[\"test value\"]"
string dbValue2 = "[\"one value\",[\"another value|or this value\"]]"
int dbValue3 = 1
bool dbValue4 = true
而且我需要将这些值反序列化为TestModel.TestValue
属性,以便在序列化对象时获得与数据库中存储的相同格式。我显然可以让一个int
或bool
一个基本数组工作,但在稍微复杂一点的数组的情况下我不能。从dbValue2
上面我希望输出是:
"testValue" : ["one value",["another value|or this value"]]
现在,我正在使用 ServiceStack.Text 到目前为止,这是我尝试过的:
TestValue = JsonSerializer.DeserializeFromString(dbValue, typeof(object))
TestValue = dbValue.FromJson<object>()
TestValue = JsonObject.Parse(dbValue)
这些产生:
"testValue":"[one value,[another value|or this value]]"
"testValue":{"one value":["another value|or this value"]}
"testValue":{"one value":["another value|or this value"]}
我可以理解为什么这些不起作用,但我不知道如何做我需要的。
任何帮助将非常感激。