iOS Question Change in JSON handling of null value in v5?

Discussion in 'iOS Questions' started by nwhitfield, May 18, 2018 at 11:08 AM.

Tags:
  1. nwhitfield

    nwhitfield Active Member Licensed User

    Has there been a tweak in how JSON - particularly null values - are handled?

    In the API that my iOS project talks to, a field may be blank, or not present; in the returned data from the server, it's usually present, but may have the value set to null, (not quoted) in the JSON, rather than an empty string. For reasons I haven't dug into too much, if a null value was then posted back via the B4i app, it would be converted to a string value of "null" somewhere along the way.

    That was straightforward enough to work around, and I thought I'd fixed everything up, then I recompiled the app with v5, and a bug related to null values reappeared. It seems that now, a null value in JSON will be converted to the string value "<null>"

    Am I right that that's changed? Certainly tweaking my code to treat both "null" and "<null>" the same has fixed the problem. I guess it's a small change, but if you're flinging JSON around a lot, it could cause odd behaviour.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    I see the cause of this issue. I don't think that it worked differently in previous versions. It does work differently in debug mode (depending on some parameters).

    Use this code to check whether a value field is null:
    Code:
    Sub IsNull(m As Map, key As StringAs Boolean
       
    Dim value As Object = m.Get("key")
       
    If value = Null Or GetType(value) = "NSNull" Then Return True
       
    Return False
    End Sub
    Code:
    If IsNull(MyMap, "SomeKey"Then ...
     
    nwhitfield likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice