locked
How can i read a blank string using JObject ? RRS feed

  • Question

  • User1253338400 posted

    Hi ,

    I user the following 

    var dataValue  = JObject.Parse(configfile);

    if config file is empty string it gives an error , how can i return just empty for dataValue ?

    thanks

    Wednesday, April 29, 2020 7:07 AM

Answers

  • User-17257777 posted

    Hi robby32,

    If configfile is null (or empty), then JObject.Parse() will throw an exception because null is not a valid JSON string.

    I think you can use string.IsNullOrEmpty() first to check the value. If it is not null or empty, then use JObject.Parse().

    Best Regards,

    Jiadong Meng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 29, 2020 7:58 AM