Converting JSON string to C# object/array











up vote
0
down vote

favorite












I am looking to convert the following data into a c# object or array in which i can display each item (eventually to be displayed in a list view).



the json itself looks like this:



[
{
"commonName": "uni_comp_4",
"processorID": "BFEFBDEB001201"
},
{
"commonName": "lib_comp_12",
"processorID": "BFEFBDEB004323"
}
]


I have looked here for help however I think I may have to take another approach as my system is slightly different.



I'm using a class:



public class API_Response
{
public bool IsError { get; set; }
public string ErrorMessage { get; set;
public dynamic ResponseData { get; set; }
}


for data carrying. My JSON "data" is as shown above however I have been having issues deserialising this.



Initially, I tried:



API_Response r = JsonConvert.DeserializeObject<API_Response>(response);


and I'm able to see the JSON string with MessageBox.show(r.ResponseData). Which inherently is not deserialised.



Additionally, I have tried declaring the following in the same method:



public class RootObject
{
public string commonName { get; set; }
public string processorID { get; set; }
}


with no luck in displaying this data individually (or at all).



Essentially, I'm trying to put class API_Response's "ResponseData" into an object and I'm having difficulty.










share|improve this question




















  • 6




    JsonConvert.DeserializeObject<List<RootObject>>(response);
    – Sir Rufo
    Nov 19 at 1:43










  • im using API_Response to get the data, i think i maybe have to put the RootObject inside the API_Response Class? so that i can separate the response into CommonName and Processor ?
    – Cragie
    Nov 19 at 1:50















up vote
0
down vote

favorite












I am looking to convert the following data into a c# object or array in which i can display each item (eventually to be displayed in a list view).



the json itself looks like this:



[
{
"commonName": "uni_comp_4",
"processorID": "BFEFBDEB001201"
},
{
"commonName": "lib_comp_12",
"processorID": "BFEFBDEB004323"
}
]


I have looked here for help however I think I may have to take another approach as my system is slightly different.



I'm using a class:



public class API_Response
{
public bool IsError { get; set; }
public string ErrorMessage { get; set;
public dynamic ResponseData { get; set; }
}


for data carrying. My JSON "data" is as shown above however I have been having issues deserialising this.



Initially, I tried:



API_Response r = JsonConvert.DeserializeObject<API_Response>(response);


and I'm able to see the JSON string with MessageBox.show(r.ResponseData). Which inherently is not deserialised.



Additionally, I have tried declaring the following in the same method:



public class RootObject
{
public string commonName { get; set; }
public string processorID { get; set; }
}


with no luck in displaying this data individually (or at all).



Essentially, I'm trying to put class API_Response's "ResponseData" into an object and I'm having difficulty.










share|improve this question




















  • 6




    JsonConvert.DeserializeObject<List<RootObject>>(response);
    – Sir Rufo
    Nov 19 at 1:43










  • im using API_Response to get the data, i think i maybe have to put the RootObject inside the API_Response Class? so that i can separate the response into CommonName and Processor ?
    – Cragie
    Nov 19 at 1:50













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am looking to convert the following data into a c# object or array in which i can display each item (eventually to be displayed in a list view).



the json itself looks like this:



[
{
"commonName": "uni_comp_4",
"processorID": "BFEFBDEB001201"
},
{
"commonName": "lib_comp_12",
"processorID": "BFEFBDEB004323"
}
]


I have looked here for help however I think I may have to take another approach as my system is slightly different.



I'm using a class:



public class API_Response
{
public bool IsError { get; set; }
public string ErrorMessage { get; set;
public dynamic ResponseData { get; set; }
}


for data carrying. My JSON "data" is as shown above however I have been having issues deserialising this.



Initially, I tried:



API_Response r = JsonConvert.DeserializeObject<API_Response>(response);


and I'm able to see the JSON string with MessageBox.show(r.ResponseData). Which inherently is not deserialised.



Additionally, I have tried declaring the following in the same method:



public class RootObject
{
public string commonName { get; set; }
public string processorID { get; set; }
}


with no luck in displaying this data individually (or at all).



Essentially, I'm trying to put class API_Response's "ResponseData" into an object and I'm having difficulty.










share|improve this question















I am looking to convert the following data into a c# object or array in which i can display each item (eventually to be displayed in a list view).



the json itself looks like this:



[
{
"commonName": "uni_comp_4",
"processorID": "BFEFBDEB001201"
},
{
"commonName": "lib_comp_12",
"processorID": "BFEFBDEB004323"
}
]


I have looked here for help however I think I may have to take another approach as my system is slightly different.



I'm using a class:



public class API_Response
{
public bool IsError { get; set; }
public string ErrorMessage { get; set;
public dynamic ResponseData { get; set; }
}


for data carrying. My JSON "data" is as shown above however I have been having issues deserialising this.



Initially, I tried:



API_Response r = JsonConvert.DeserializeObject<API_Response>(response);


and I'm able to see the JSON string with MessageBox.show(r.ResponseData). Which inherently is not deserialised.



Additionally, I have tried declaring the following in the same method:



public class RootObject
{
public string commonName { get; set; }
public string processorID { get; set; }
}


with no luck in displaying this data individually (or at all).



Essentially, I'm trying to put class API_Response's "ResponseData" into an object and I'm having difficulty.







c# json json-deserialization






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 2:41









John

10.5k31734




10.5k31734










asked Nov 19 at 1:40









Cragie

74




74








  • 6




    JsonConvert.DeserializeObject<List<RootObject>>(response);
    – Sir Rufo
    Nov 19 at 1:43










  • im using API_Response to get the data, i think i maybe have to put the RootObject inside the API_Response Class? so that i can separate the response into CommonName and Processor ?
    – Cragie
    Nov 19 at 1:50














  • 6




    JsonConvert.DeserializeObject<List<RootObject>>(response);
    – Sir Rufo
    Nov 19 at 1:43










  • im using API_Response to get the data, i think i maybe have to put the RootObject inside the API_Response Class? so that i can separate the response into CommonName and Processor ?
    – Cragie
    Nov 19 at 1:50








6




6




JsonConvert.DeserializeObject<List<RootObject>>(response);
– Sir Rufo
Nov 19 at 1:43




JsonConvert.DeserializeObject<List<RootObject>>(response);
– Sir Rufo
Nov 19 at 1:43












im using API_Response to get the data, i think i maybe have to put the RootObject inside the API_Response Class? so that i can separate the response into CommonName and Processor ?
– Cragie
Nov 19 at 1:50




im using API_Response to get the data, i think i maybe have to put the RootObject inside the API_Response Class? so that i can separate the response into CommonName and Processor ?
– Cragie
Nov 19 at 1:50












4 Answers
4






active

oldest

votes

















up vote
0
down vote













Shouldn't you deserialize into RootObject, rather than API_Response? Also, depending on the settings you may need to have C# variables in Pascal casing, that is CommonName and ProcessorID






share|improve this answer























  • API_Response's "ResponseData" is what i think i need to deserialise, RootObject isnt linked in any form at the moment
    – Cragie
    Nov 19 at 1:51






  • 2




    @Cragie Computers are totally dumb. They will follow your code and not your thougths. If there is something related to RootObject you have to code that
    – Sir Rufo
    Nov 19 at 1:59


















up vote
0
down vote













You are trying to deserialize the object with the class which doesn't have elements mentioned in the JSON. Try to put List<RootObject> because your JSON contains the list of the RootObject class that you have created. Try the below solution if it works for you.



JsonConvert.DeserializeObject<List<RootObject>>(response);





share|improve this answer























  • Am i supposed to run this command in order to make the alteration or must I set this to a variable? I set it to a "dynamic" variable and then tried to print it however i received this error: "{"Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[infosecQuiz.authorisationMenu+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.rnTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive ty...
    – Cragie
    Nov 19 at 18:58




















up vote
-1
down vote













just use a decoder to decode the message



Struct PCS: Decodable
{
let commonName : String?
let proccesorID : String?

}

var pcs = [PCS]()


put this in viewdidload



func parseData(){

let jsonUrlString = "Your_API_URL"
guard let url = URL(string: jsonUrlString) else { return }

URLSession.shared.dataTask(with: url) {(data, response, err) in

guard let data = data else { return }

do {

let decoder = JSONDecoder()
pcs = try decoder.decode([Course].self, from: data)

DispatchQueue.main.async {

self.tableView.reloadData()

}


} catch let jsonErr{
print("error", jsonErr)
}


}.resume()


in tableView
call the data like this



pcs[indexPath.row].commonName





share|improve this answer





















  • The OP was looking for answer using C#. This looks like swift.
    – Brian Rogers
    Nov 19 at 15:54


















up vote
-1
down vote



accepted










public class RootObject{
public string commonName { get; set; }
public string processorID { get; set; }
}

public class API_Response
{
public bool IsError { get; set; }
public string ErrorMessage { get; set; }
public RootObject ResponseData { get; set; }
}


API_Response r = JsonConvert.DeserializeObject<API_Response>(response);


I can then use this format for calling the data



MessageBox.Show("" + r.ResponseData[0].commonName);





share|improve this answer

















  • 1




    Nope, this will only result in an exception .Net Fiddle example ... or you present us the wrong json response string in your question - this example works
    – Sir Rufo
    Nov 20 at 8:00













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53367255%2fconverting-json-string-to-c-sharp-object-array%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Shouldn't you deserialize into RootObject, rather than API_Response? Also, depending on the settings you may need to have C# variables in Pascal casing, that is CommonName and ProcessorID






share|improve this answer























  • API_Response's "ResponseData" is what i think i need to deserialise, RootObject isnt linked in any form at the moment
    – Cragie
    Nov 19 at 1:51






  • 2




    @Cragie Computers are totally dumb. They will follow your code and not your thougths. If there is something related to RootObject you have to code that
    – Sir Rufo
    Nov 19 at 1:59















up vote
0
down vote













Shouldn't you deserialize into RootObject, rather than API_Response? Also, depending on the settings you may need to have C# variables in Pascal casing, that is CommonName and ProcessorID






share|improve this answer























  • API_Response's "ResponseData" is what i think i need to deserialise, RootObject isnt linked in any form at the moment
    – Cragie
    Nov 19 at 1:51






  • 2




    @Cragie Computers are totally dumb. They will follow your code and not your thougths. If there is something related to RootObject you have to code that
    – Sir Rufo
    Nov 19 at 1:59













up vote
0
down vote










up vote
0
down vote









Shouldn't you deserialize into RootObject, rather than API_Response? Also, depending on the settings you may need to have C# variables in Pascal casing, that is CommonName and ProcessorID






share|improve this answer














Shouldn't you deserialize into RootObject, rather than API_Response? Also, depending on the settings you may need to have C# variables in Pascal casing, that is CommonName and ProcessorID







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 at 2:43









Prix

15.8k1252112




15.8k1252112










answered Nov 19 at 1:44









Felix

2,31222760




2,31222760












  • API_Response's "ResponseData" is what i think i need to deserialise, RootObject isnt linked in any form at the moment
    – Cragie
    Nov 19 at 1:51






  • 2




    @Cragie Computers are totally dumb. They will follow your code and not your thougths. If there is something related to RootObject you have to code that
    – Sir Rufo
    Nov 19 at 1:59


















  • API_Response's "ResponseData" is what i think i need to deserialise, RootObject isnt linked in any form at the moment
    – Cragie
    Nov 19 at 1:51






  • 2




    @Cragie Computers are totally dumb. They will follow your code and not your thougths. If there is something related to RootObject you have to code that
    – Sir Rufo
    Nov 19 at 1:59
















API_Response's "ResponseData" is what i think i need to deserialise, RootObject isnt linked in any form at the moment
– Cragie
Nov 19 at 1:51




API_Response's "ResponseData" is what i think i need to deserialise, RootObject isnt linked in any form at the moment
– Cragie
Nov 19 at 1:51




2




2




@Cragie Computers are totally dumb. They will follow your code and not your thougths. If there is something related to RootObject you have to code that
– Sir Rufo
Nov 19 at 1:59




@Cragie Computers are totally dumb. They will follow your code and not your thougths. If there is something related to RootObject you have to code that
– Sir Rufo
Nov 19 at 1:59












up vote
0
down vote













You are trying to deserialize the object with the class which doesn't have elements mentioned in the JSON. Try to put List<RootObject> because your JSON contains the list of the RootObject class that you have created. Try the below solution if it works for you.



JsonConvert.DeserializeObject<List<RootObject>>(response);





share|improve this answer























  • Am i supposed to run this command in order to make the alteration or must I set this to a variable? I set it to a "dynamic" variable and then tried to print it however i received this error: "{"Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[infosecQuiz.authorisationMenu+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.rnTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive ty...
    – Cragie
    Nov 19 at 18:58

















up vote
0
down vote













You are trying to deserialize the object with the class which doesn't have elements mentioned in the JSON. Try to put List<RootObject> because your JSON contains the list of the RootObject class that you have created. Try the below solution if it works for you.



JsonConvert.DeserializeObject<List<RootObject>>(response);





share|improve this answer























  • Am i supposed to run this command in order to make the alteration or must I set this to a variable? I set it to a "dynamic" variable and then tried to print it however i received this error: "{"Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[infosecQuiz.authorisationMenu+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.rnTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive ty...
    – Cragie
    Nov 19 at 18:58















up vote
0
down vote










up vote
0
down vote









You are trying to deserialize the object with the class which doesn't have elements mentioned in the JSON. Try to put List<RootObject> because your JSON contains the list of the RootObject class that you have created. Try the below solution if it works for you.



JsonConvert.DeserializeObject<List<RootObject>>(response);





share|improve this answer














You are trying to deserialize the object with the class which doesn't have elements mentioned in the JSON. Try to put List<RootObject> because your JSON contains the list of the RootObject class that you have created. Try the below solution if it works for you.



JsonConvert.DeserializeObject<List<RootObject>>(response);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 at 15:48









Brian Rogers

72.5k17184198




72.5k17184198










answered Nov 19 at 3:49









Zeeshan Ali

13




13












  • Am i supposed to run this command in order to make the alteration or must I set this to a variable? I set it to a "dynamic" variable and then tried to print it however i received this error: "{"Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[infosecQuiz.authorisationMenu+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.rnTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive ty...
    – Cragie
    Nov 19 at 18:58




















  • Am i supposed to run this command in order to make the alteration or must I set this to a variable? I set it to a "dynamic" variable and then tried to print it however i received this error: "{"Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[infosecQuiz.authorisationMenu+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.rnTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive ty...
    – Cragie
    Nov 19 at 18:58


















Am i supposed to run this command in order to make the alteration or must I set this to a variable? I set it to a "dynamic" variable and then tried to print it however i received this error: "{"Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[infosecQuiz.authorisationMenu+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.rnTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive ty...
– Cragie
Nov 19 at 18:58






Am i supposed to run this command in order to make the alteration or must I set this to a variable? I set it to a "dynamic" variable and then tried to print it however i received this error: "{"Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[infosecQuiz.authorisationMenu+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.rnTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive ty...
– Cragie
Nov 19 at 18:58












up vote
-1
down vote













just use a decoder to decode the message



Struct PCS: Decodable
{
let commonName : String?
let proccesorID : String?

}

var pcs = [PCS]()


put this in viewdidload



func parseData(){

let jsonUrlString = "Your_API_URL"
guard let url = URL(string: jsonUrlString) else { return }

URLSession.shared.dataTask(with: url) {(data, response, err) in

guard let data = data else { return }

do {

let decoder = JSONDecoder()
pcs = try decoder.decode([Course].self, from: data)

DispatchQueue.main.async {

self.tableView.reloadData()

}


} catch let jsonErr{
print("error", jsonErr)
}


}.resume()


in tableView
call the data like this



pcs[indexPath.row].commonName





share|improve this answer





















  • The OP was looking for answer using C#. This looks like swift.
    – Brian Rogers
    Nov 19 at 15:54















up vote
-1
down vote













just use a decoder to decode the message



Struct PCS: Decodable
{
let commonName : String?
let proccesorID : String?

}

var pcs = [PCS]()


put this in viewdidload



func parseData(){

let jsonUrlString = "Your_API_URL"
guard let url = URL(string: jsonUrlString) else { return }

URLSession.shared.dataTask(with: url) {(data, response, err) in

guard let data = data else { return }

do {

let decoder = JSONDecoder()
pcs = try decoder.decode([Course].self, from: data)

DispatchQueue.main.async {

self.tableView.reloadData()

}


} catch let jsonErr{
print("error", jsonErr)
}


}.resume()


in tableView
call the data like this



pcs[indexPath.row].commonName





share|improve this answer





















  • The OP was looking for answer using C#. This looks like swift.
    – Brian Rogers
    Nov 19 at 15:54













up vote
-1
down vote










up vote
-1
down vote









just use a decoder to decode the message



Struct PCS: Decodable
{
let commonName : String?
let proccesorID : String?

}

var pcs = [PCS]()


put this in viewdidload



func parseData(){

let jsonUrlString = "Your_API_URL"
guard let url = URL(string: jsonUrlString) else { return }

URLSession.shared.dataTask(with: url) {(data, response, err) in

guard let data = data else { return }

do {

let decoder = JSONDecoder()
pcs = try decoder.decode([Course].self, from: data)

DispatchQueue.main.async {

self.tableView.reloadData()

}


} catch let jsonErr{
print("error", jsonErr)
}


}.resume()


in tableView
call the data like this



pcs[indexPath.row].commonName





share|improve this answer












just use a decoder to decode the message



Struct PCS: Decodable
{
let commonName : String?
let proccesorID : String?

}

var pcs = [PCS]()


put this in viewdidload



func parseData(){

let jsonUrlString = "Your_API_URL"
guard let url = URL(string: jsonUrlString) else { return }

URLSession.shared.dataTask(with: url) {(data, response, err) in

guard let data = data else { return }

do {

let decoder = JSONDecoder()
pcs = try decoder.decode([Course].self, from: data)

DispatchQueue.main.async {

self.tableView.reloadData()

}


} catch let jsonErr{
print("error", jsonErr)
}


}.resume()


in tableView
call the data like this



pcs[indexPath.row].commonName






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 3:43









Zack Cheang Weng Seong

308




308












  • The OP was looking for answer using C#. This looks like swift.
    – Brian Rogers
    Nov 19 at 15:54


















  • The OP was looking for answer using C#. This looks like swift.
    – Brian Rogers
    Nov 19 at 15:54
















The OP was looking for answer using C#. This looks like swift.
– Brian Rogers
Nov 19 at 15:54




The OP was looking for answer using C#. This looks like swift.
– Brian Rogers
Nov 19 at 15:54










up vote
-1
down vote



accepted










public class RootObject{
public string commonName { get; set; }
public string processorID { get; set; }
}

public class API_Response
{
public bool IsError { get; set; }
public string ErrorMessage { get; set; }
public RootObject ResponseData { get; set; }
}


API_Response r = JsonConvert.DeserializeObject<API_Response>(response);


I can then use this format for calling the data



MessageBox.Show("" + r.ResponseData[0].commonName);





share|improve this answer

















  • 1




    Nope, this will only result in an exception .Net Fiddle example ... or you present us the wrong json response string in your question - this example works
    – Sir Rufo
    Nov 20 at 8:00

















up vote
-1
down vote



accepted










public class RootObject{
public string commonName { get; set; }
public string processorID { get; set; }
}

public class API_Response
{
public bool IsError { get; set; }
public string ErrorMessage { get; set; }
public RootObject ResponseData { get; set; }
}


API_Response r = JsonConvert.DeserializeObject<API_Response>(response);


I can then use this format for calling the data



MessageBox.Show("" + r.ResponseData[0].commonName);





share|improve this answer

















  • 1




    Nope, this will only result in an exception .Net Fiddle example ... or you present us the wrong json response string in your question - this example works
    – Sir Rufo
    Nov 20 at 8:00















up vote
-1
down vote



accepted







up vote
-1
down vote



accepted






public class RootObject{
public string commonName { get; set; }
public string processorID { get; set; }
}

public class API_Response
{
public bool IsError { get; set; }
public string ErrorMessage { get; set; }
public RootObject ResponseData { get; set; }
}


API_Response r = JsonConvert.DeserializeObject<API_Response>(response);


I can then use this format for calling the data



MessageBox.Show("" + r.ResponseData[0].commonName);





share|improve this answer












public class RootObject{
public string commonName { get; set; }
public string processorID { get; set; }
}

public class API_Response
{
public bool IsError { get; set; }
public string ErrorMessage { get; set; }
public RootObject ResponseData { get; set; }
}


API_Response r = JsonConvert.DeserializeObject<API_Response>(response);


I can then use this format for calling the data



MessageBox.Show("" + r.ResponseData[0].commonName);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 23:52









Cragie

74




74








  • 1




    Nope, this will only result in an exception .Net Fiddle example ... or you present us the wrong json response string in your question - this example works
    – Sir Rufo
    Nov 20 at 8:00
















  • 1




    Nope, this will only result in an exception .Net Fiddle example ... or you present us the wrong json response string in your question - this example works
    – Sir Rufo
    Nov 20 at 8:00










1




1




Nope, this will only result in an exception .Net Fiddle example ... or you present us the wrong json response string in your question - this example works
– Sir Rufo
Nov 20 at 8:00






Nope, this will only result in an exception .Net Fiddle example ... or you present us the wrong json response string in your question - this example works
– Sir Rufo
Nov 20 at 8:00




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53367255%2fconverting-json-string-to-c-sharp-object-array%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft