0

I am attempting to use the API from a 3rd party website to retrieve information, unfortunately it provides way more information that I need. from my understanding of the java deserializer, the class needs to exactly match the json string to parse properly. I was wondering if there was a way to retrieve only the values I am interested in without having to do a ton of string splitting.

example:

//my class
class message
{
    public string id { get; set; }
    public string author { get; set; }
    public string body { get; set; }
}

// json string

{
        "body": "this is test 2", 
        "was_comment": false, 
        "first_message": null, 
        "name": "name", 
        "first_message_name": null, 
        "created": 1402707862.0, 
        "dest": "recipiant", 
        "author": "author", 
        "parent_id": null, 
        "context": "", 
        "replies": "", 
        "new": true, 
        "id": "das9deh", 
        "subject": "test2"
    }

as you can see there is a substantial amount of information in the json string that I do not need for my purposes, so I was wondering if there is an efficient way to simply pull out the id,author, and body values directly to my class.

This is why my question is different:

I get a large json string from a 3rd party that I want to deserialize. my question is, how to deserialize without having a class that exactly matches the json string as I only need selected values.

in the proposed solution is the opposite of the answer I'm looking for

tcooc
  • 20,629
  • 3
  • 39
  • 57
user2835725
  • 154
  • 6
  • I have found countless references to how to parse a json line, but I am unable to find any reference to only parsing certain values from a json string. – user2835725 Jun 13 '14 at 17:32
  • Not without the developers of this 3rd party going in and changing the api. You can probably submit a request to them for this to be a feature, but they will not likely change it. Make sure that they do not offer a different method you could use to get only the data you need, or if you tell us what API you are using, maybe we could check. – MIke Jun 13 '14 at 17:44

0 Answers0