Serialize an object directly to a JObject instead of to a string in json.net

后端 未结 3 1707
天涯浪人
天涯浪人 2021-02-03 19:11

How might one serialize an object directly to a JObject instance in JSON.Net? What is typically done is to convert the object directly to a json string lik

3条回答
  •  礼貌的吻别
    2021-02-03 19:44

    To combine everything: use JToken for everything (Objects AND Arrays).

    JToken token = JToken.FromObject(someObjectOrArray);
    

    Then check through token.Type which JTokenType it is (Object, Array or otherwise).

提交回复
热议问题