Parsing JSON
-
I am trying to parse the following JSON string, to get the genre, id, and photo in a list. [ { id: "6" genre: "Music" photo: "music.jpg" }, { id: "2" genre: "Entertainment" photo: "enter.png" }, { id: "8" genre: "Games" photo: "games.gif" }, { id: "7" genre: "Movies" photo: "movie.gif" }, { id: "9" genre: "News" photo: "news.jpg" }, { id: "5" genre: "Mail" photo: "Mail.gif" } ] I tried using the JSON.Net library, but could not really use it, due to lack of examples. If anyone can help in getting the id, genre, and photo in a list, that would be really helpful! *Also, I am using the Compact Framework, WM 6. Thanks, Harsimran Singh
- The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. - Ted Nelson 2) Why is it drug addicts and computer afficionados are both called users? - Clifford Stoll 3) The real danger is not that computers will begin to think like men, but that men will begin to think like computers. - Sydney J. Harris (Computer code: 00001111 - translation: Hello! :P ) REMEMBER: "Computers are made for us, we are not made for them
-
I am trying to parse the following JSON string, to get the genre, id, and photo in a list. [ { id: "6" genre: "Music" photo: "music.jpg" }, { id: "2" genre: "Entertainment" photo: "enter.png" }, { id: "8" genre: "Games" photo: "games.gif" }, { id: "7" genre: "Movies" photo: "movie.gif" }, { id: "9" genre: "News" photo: "news.jpg" }, { id: "5" genre: "Mail" photo: "Mail.gif" } ] I tried using the JSON.Net library, but could not really use it, due to lack of examples. If anyone can help in getting the id, genre, and photo in a list, that would be really helpful! *Also, I am using the Compact Framework, WM 6. Thanks, Harsimran Singh
- The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. - Ted Nelson 2) Why is it drug addicts and computer afficionados are both called users? - Clifford Stoll 3) The real danger is not that computers will begin to think like men, but that men will begin to think like computers. - Sydney J. Harris (Computer code: 00001111 - translation: Hello! :P ) REMEMBER: "Computers are made for us, we are not made for them
Have you looked at JavaScript Object Notation Support for .NET 2.0[^]
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
I am trying to parse the following JSON string, to get the genre, id, and photo in a list. [ { id: "6" genre: "Music" photo: "music.jpg" }, { id: "2" genre: "Entertainment" photo: "enter.png" }, { id: "8" genre: "Games" photo: "games.gif" }, { id: "7" genre: "Movies" photo: "movie.gif" }, { id: "9" genre: "News" photo: "news.jpg" }, { id: "5" genre: "Mail" photo: "Mail.gif" } ] I tried using the JSON.Net library, but could not really use it, due to lack of examples. If anyone can help in getting the id, genre, and photo in a list, that would be really helpful! *Also, I am using the Compact Framework, WM 6. Thanks, Harsimran Singh
- The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. - Ted Nelson 2) Why is it drug addicts and computer afficionados are both called users? - Clifford Stoll 3) The real danger is not that computers will begin to think like men, but that men will begin to think like computers. - Sydney J. Harris (Computer code: 00001111 - translation: Hello! :P ) REMEMBER: "Computers are made for us, we are not made for them
The JSON.Net library isn't too hard to use. The documentation can be a bit hard to follow at times, but at lot of the mess comes from the really bad LINQ examples. Create a class to encapsulate the id, genre, and photo fields. I'll just call it Section for this example. Then use this code to get your list of Section objects:
List<Section> products = JsonConvert.DeserializeObject<List<Section>>(jsonString);
-
The JSON.Net library isn't too hard to use. The documentation can be a bit hard to follow at times, but at lot of the mess comes from the really bad LINQ examples. Create a class to encapsulate the id, genre, and photo fields. I'll just call it Section for this example. Then use this code to get your list of Section objects:
List<Section> products = JsonConvert.DeserializeObject<List<Section>>(jsonString);
Thanks! That worked perfectly for me!! :-D
- The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. - Ted Nelson 2) Why is it drug addicts and computer afficionados are both called users? - Clifford Stoll 3) The real danger is not that computers will begin to think like men, but that men will begin to think like computers. - Sydney J. Harris (Computer code: 00001111 - translation: Hello! :P ) REMEMBER: "Computers are made for us, we are not made for them