1

using JSON.net I could do this as answered in this link

string content = File.ReadAllText(path);
var token = JToken.Parse(content);

if (token is JArray)
{
    IEnumerable<Phone> phones = token.ToObject<List<Phone>>();
}
else if (token is JObject)
{
    Phone phone = token.ToObject<Phone>();
}

but is there a way i could do it similarly in ServiceStack.Text library?

1 Answer 1

3

You could do it like this:

string content = File.ReadAllText(path);

if (JsonUtils.IsJsArray(content))
{
    IEnumerable<Phone> phones = JsonSerializer.DeserializeFromString<List<Phone>>(json);
}
else if (JsonUtils.IsJsObject(content))
{
    Phone phone = JsonSerializer.DeserializeFromString<Phone>(json);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.