How to parse HttpWebResponse string into a class ?

  • Thread starter Thread starter aujong
  • Start date Start date
A

aujong

Guest
Our application is written in .NET 2010.
It is using HTTPWebResponse to get a string from a URL.
Here is an example of the string:
{"responseStatus":"SUCCESS","statusCode":200,
"paymentCards":
[{"cardReference":"abc","cardType":"MASTERCARD","expiryDate":"02/20"}],
"maxNumberOfCards":3}

The string format is like below:

public enum ResponseStatus {
SUCCESS,
FAILURE;
}

private final ResponseStatus responseStatus;
private final int statusCode;
private List<Card> Cards;
private int maxNumberOfCards;

//And a Card looks like:

private String cardReference;
private String cardType;
private String expiryDate;

//This is to get the string from the URL using HttpWebResponse:
request= (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
response = (HttpWebResponse) request.GetResponse();
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadToEnd();


What is the best way to parse "Line" ?

Thank you

Continue reading...
 
Back
Top