Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7030797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:43:09+00:00 2026-05-28T00:43:09+00:00

I am using Newtonsoft.Json to Deserialize json string to Object, but I can’t judge

  • 0

I am using Newtonsoft.Json to Deserialize json string to Object, but I can’t judge if the node is null or not. eg. jo["data"]["prevtime"], sometimes json has the node of ["prevtime"], sometimes doesn’t have ["prevtime"]. If ["prevtime"] is null, it will report an error.

var jo = JObject.Parse(content);
if (jo["data"].ToString() == "")
    return new StatusCollection();

var jInfo = jo["data"]["info"];
StatusCollection list = new StatusCollection();
Status status = null;

if (jInfo != null)
{
    foreach (var j in jInfo.Children())
    {

       if (jo["data"]["prevtime"] != null) 
       {
           status.Nexttime = jo["data"]["nexttime"].ToString();
           status.Prevtime = jo["data"]["prevtime"].ToString();
       }

       status = j.ToObject<Status>();
       if (!string.IsNullOrEmpty(status.Head))
       {
           status.Head += "/50";
       }
       if (!string.IsNullOrEmpty(status.From))
       {
           status.From = "来自" + status.From;
       }
       list.Add(status);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:43:09+00:00Added an answer on May 28, 2026 at 12:43 am

    Try to select the token you want, and there is a property to get the token value

    if (jo["data"].Select("prevtime") != null) 
    {
            status.Prevtime = jo["data"].Value<string>("prevtime");
            status.Nexttime = jo["data"].Value<string>("nexttime");
    }
    

    JSON.NET Documentation:

    Link 1

    Link 2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Newtonsoft's Json.NET to deserialize a JSON string: var output = JsonConvert.DeserializeObject<dynamic>({
Is there is any other way deserialize JSON string,rather than using the Newtonsoft library?
I've serialized an object using Newtonsoft's JSON serializer, and the DateTime has come through
I am trying to populate a C# object (ImportedProductCodesContainer) with data using JSON.NET deserialization.
I am using Newtonsoft Json library to parse json but i don't know how
Parsing Google Plus JSON objects Using C# and Newtonsoft.Json library how one can parse
I'm using Newtonsoft.Json.Linq and I'd like to load the data into objects (or structs)
Currently I am using the terrific Linq 2 Json.net (by newtonsoft), which is a
I'm using JSON.NET implementation to serialize/deserialize .NET objects to JS and vice versa, all
Please see: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Converters;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.