Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize JSON output #93

Closed
anguoyang opened this issue Mar 28, 2016 · 7 comments
Closed

Deserialize JSON output #93

anguoyang opened this issue Mar 28, 2016 · 7 comments

Comments

@anguoyang
Copy link

Hi, all,
I am using C# to deserialize the json output from dede server, but always return "null", I defined the Json object as follow:

    [DataContract]
    [Serializable]
    public class head
    {
        [DataMember]
        public string method { get; set; }
        [DataMember]
        public int time { get; set; }
        [DataMember]
        public string service { get; set; }

    }

    [DataContract]
    [Serializable]
    public class status
    {
        public status() 
        {
            this.code = 0;
            this.msg = "";
        }
        [DataMember]
        public int code { get; set; }
        [DataMember]
        public string msg { get; set; }

    }

    [DataContract]
    [Serializable]
    public class probs
    {
        public probs() 
        {
            this.prob = 0.0;
            this.cat = "";
        }
        [DataMember]
        public double prob { get; set; }
        [DataMember]
        public string cat { get; set; }

    }

    [DataContract]
    [Serializable]
    public class classes
    {
        [DataMember]
        public probs[] _probs { get; set; }

    }

    [DataContract]
    [Serializable]
    public class predictions
    {
        public predictions() 
        {
            this._classes = new classes();
            this.uri = "";
            this.loss = 0;
        }

        [DataMember]
        public string uri { get; set; }
        [DataMember]
        public int loss { get; set; }
        [DataMember]
        public classes _classes { get; set; }
    }

    [DataContract]
    [Serializable]
    public class body
    {
        public body() 
        {
            this._predictions = new predictions();
        }
        [DataMember]
        public predictions _predictions { get; set; }

    }

    [DataContract]
    [Serializable]
    public class JSonPredictData
    {
        public JSonPredictData() 
        {
            this._status = new status();
            this._head = new head();
            this._body = new body();
        }

        [DataMember]
        public body _body { get; set; }

        [DataMember]
        public head _head { get; set; }

        [DataMember]
        public status _status { get; set; }

    }

and using NewtonSoft to deserialize it:
JSonPredictData result = (JSonPredictData)JsonConvert.DeserializeObject(JsonString, typeof(JSonPredictData));

Here, the JsonSting is:

{"status":{"code":200,"msg":"OK"},"head":{"method":"/predict","time":33061.0,"se
rvice":"imageserv"},"body":{"predictions":{"uri":"http://www.deepdetect.com/img/
ambulance.jpg","classes":[{"prob":0.9928520321846008,"cat":"n02701002 ambulance"
},{"prob":0.0069321757182478909,"cat":"n03977966 police van, police wagon, paddy
wagon, patrol wagon, wagon, black Maria"},{"last":true,"prob":0.000069531641202
04747,"cat":"n03769881 minibus"}]}}}

What is wrong with my class definition? thanks.

@anguoyang
Copy link
Author

JSonPredictData result = (JSonPredictData)JsonConvert.DeserializeObject(JsonString, typeof(JSonPredictData));

The result always return null.

@beniz
Copy link
Collaborator

beniz commented Mar 28, 2016

If I understand correctly, dd works fine, and there's an issue with your client code ? If so, you may get more attention on a .Net forum or on stackoverflow...
There's no C# official dd client on the roadmap yet, but if you decide that you would like to take the opportunity to write and share one, we'll help as possible.

@anguoyang
Copy link
Author

hi,@beniz,I would like to share the code, pull request it in about 2days

@beniz
Copy link
Collaborator

beniz commented Apr 4, 2016

hi @anguoyang any difficulties with a C# client ? Just wondering if I should rename / refocus this ticket on a C# client to the dd API ?

@anguoyang
Copy link
Author

hi @beniz , Sorry for the late, I have just commit the source code and send the pull request, please check it, thanks a lot.

@beniz
Copy link
Collaborator

beniz commented Apr 4, 2016

hi @anguoyang thanks, I guess this is the code here: anguoyang@3839d39

You'd need to PR it to fit into the dd repository, or maybe easier, to make an external repository of it (e.g. deepdetect-csharp-client) and then we can review it together, test it etc...

As a first remark, your code appears to include possible binary files such as csharpClient.exe which should probably not be there.

@anguoyang
Copy link
Author

HI, @beniz , I have deleted the binary files and PR it into ./clients/csharp.
https://github.com/beniz/deepdetect/pull/98
Please check it, please let me know if there are still problems. Thanks.

@beniz beniz closed this as completed Apr 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants