Unable to Read JSON from OneSignal REST

Jassim Al Rahma 1,591 Reputation points
2021-11-26T12:20:54.357+00:00

Hi,

I am trying to read the JSON from:

https://onesignal.com/api/v1/notifications

One of the data is

"isHuawei": false,

I trued setting the class to:

public bool isHuawei { get; set; }

but getting:

The JSON value could not be converted to System.Boolean. Path: $.notifications[16].isHuawei | LineNumber: 0 | BytePositionInLine: 40495.

and when I try to set it to:

public string isHuawei { get; set; }
public bool onesignal_isHuawei
{
    get
    {
        return Convert.ToBoolean(isHuawei);
    }
}

I get:

The JSON value could not be converted to System.String. Path: $.notifications[0].isHuawei | LineNumber: 0 | BytePositionInLine: 1536.

so either way I am getting error.. :(

Kindly help..

Thanks,
Jassim

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,378 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,288 questions
0 comments No comments
{count} votes

Accepted answer
  1. P a u l 10,751 Reputation points
    2021-11-26T13:19:01.17+00:00

    The serialiser you're using can probably handle deserialising booleans so just change this:

    public string isHuawei { get; set; }
    

    To:

    public bool isHuawei { get; set; }
    

    Then you can just get rid of the onesignal_isHuawei property.

    EDIT: Apologies - I see you've already tried that. My guess is that there's a isHuawei property from your JSON file that's either null or undefined, but it's hard to say without seeing the JSON you're deserialising. Could you attach it here so we can see?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.