Streaming spn/spf not a double

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LiamP
    Junior Member
    • Oct 2015
    • 284

    #1

    Streaming spn/spf not a double

    Documentation lists spn/spf as the following:

    "spn": {
    "type": "number",
    "description": "Starting Price Near - The far starting price (or null if un-changed)",
    "format": "double"
    },
    "spf": {
    "type": "number",
    "description": "Starting Price Far - The far starting price (or null if un-changed)",
    "format": "double"
    },
    Yet sometimes the following is returned:

    {"spn":"Infinity","spf":"NaN","id":10660857}
    Using golang so not sure how I can get round this when parsing the json streaming response, as far as standards go I am fairly sure its not correct to vary the response from a string to a double. How are others getting around this? I can see in the example code double is used which I assume would cause an error
  • jabe
    Senior Member
    • Dec 2014
    • 705

    #2
    I haven't used Go.

    I found this https://stackoverflow.com/questions/...in-go-language
    where someone has suggested you use a type switch (which looks rather like the equivalent of Select Case (Or Evaluate, for us Cobol II oldies)).

    So something like
    Code:
    func (e *Easy)SetOption(option Option, param interface{}) {
    
        switch v := param.(type) { 
        default:
            fmt.Printf("unexpected type %T", v)
        case uint64:
            e.code = Code(C.curl_wrapper_easy_setopt_long(e.curl, C.CURLoption(option), C.long(v)))
        case string:
            e.code = Code(C.curl_wrapper_easy_setopt_str(e.curl, C.CURLoption(option), C.CString(v)))
        } 
    }
    but better. You have to check it for NULL in any case, so adding a check for text isn't going to be a huge leap.

    Maybe.

    Comment

    • LiamP
      Junior Member
      • Oct 2015
      • 284

      #3
      Hmm the issue is that I am providing a struct to a json function which then deals with the parsing. Starting to think that without rolling my own json parser and incorporating the above I don't think it's possible.

      Does the java / csharp example code error at this or can it be handled?

      Comment

      • jabe
        Senior Member
        • Dec 2014
        • 705

        #4
        I'm using VB.NET and my current program doesn't use starting prices. Perhaps someone who does use them will comment.

        The values arrive in the JSON string as a string, so in these instances you could have the receiving field defined as a string, then check the value and if it's not Null/Nan/Infinity, convert it to a double.

        This came up ( https://github.com/golang/go/issues/3480 ) when I searched, but I expect you've searched and seen it anyway.

        Comment

        Working...
        X