hello Deserialize nested JSON into C# objects - c#

"Data": [{
"timeLive": "74",
"halfTimeScore": "0 - 0",
"fullTimeScore": null,
"firstTeamToScore": null,
"homeTeamInfo": {
"homeTeam": "Atlético Mineiro",
"homeGoals": "0",
"homeGoalsHalfTime": "0",
"homeCorners": "9",
"homeYellowCards": "1",
"homeRedCards": "0",
"homeShotsGol": "3",
"homeShotsFora": "9",
"homeAttacks": "131",
"homeDangerousAttack": "49",
"homePossession": "74",
"homeFouls": 13,
"avgGoalsHome": 2.1,
"teamID": "43669",
"homeTeamForm": {
"position": "6",
"points": "33",
"form": [
"W",
"D",
"L",
"W",
"W"
]
}
},
"awayTeamInfo": {
"awayTeam": "Vasco da Gama",
"awayGoals": "0",
"awayGoalsHalfTime": "0",
"awayCorners": "1",
"awayYellowCards": "3",
"awayRedCards": "0",
"awayShotsGol": "3",
"awayShotsFora": "4",
"awayAttacks": "58",
"awayDangerousAttack": "21",
"awayPossession": "26",
"awayFouls": 14,
"avgGoalsAway": 0.9,
"teamID": "43663",
"awayTeamForm": {
"position": "15",
"points": "20",
"form": [
"W",
"L",
"L",
"L",
"D"
]
}
},
"head2head": {
"draws": 3,
"homeWins": 6,
"awayWins": 6,
"avgGolsH2H": 2.3
},
"matchEvents": [{
"eventName": "Card",
"eventType": "Yellow card",
"eventTeam": "Away",
"eventTime": 72,
"eventPlayer": {
"playerName": "Martín Silva",
"playerShortName": "M. Silva",
"playerID": "547DD"
},
"eventSubIn": null,
"eventSubOut": null,
"eventHomeTeam": false
}
]
i have the class but i don t know how to convert from json to gridview
can some one help with an exemple

If you want to do this on server side, here is the solution you need.
As your said, you have class ready or you can create class for your json using http://json2csharp.com (generate c# classes from json)
public class HomeTeamForm
{
public string position { get; set; }
public string points { get; set; }
public List<string> form { get; set; }
}
public class HomeTeamInfo
{
public string homeTeam { get; set; }
public string homeGoals { get; set; }
public string homeGoalsHalfTime { get; set; }
public string homeCorners { get; set; }
public string homeYellowCards { get; set; }
public string homeRedCards { get; set; }
public string homeShotsGol { get; set; }
public string homeShotsFora { get; set; }
public string homeAttacks { get; set; }
public string homeDangerousAttack { get; set; }
public string homePossession { get; set; }
public int homeFouls { get; set; }
public double avgGoalsHome { get; set; }
public string teamID { get; set; }
public HomeTeamForm homeTeamForm { get; set; }
}
public class AwayTeamForm
{
public string position { get; set; }
public string points { get; set; }
public List<string> form { get; set; }
}
public class AwayTeamInfo
{
public string awayTeam { get; set; }
public string awayGoals { get; set; }
public string awayGoalsHalfTime { get; set; }
public string awayCorners { get; set; }
public string awayYellowCards { get; set; }
public string awayRedCards { get; set; }
public string awayShotsGol { get; set; }
public string awayShotsFora { get; set; }
public string awayAttacks { get; set; }
public string awayDangerousAttack { get; set; }
public string awayPossession { get; set; }
public int awayFouls { get; set; }
public double avgGoalsAway { get; set; }
public string teamID { get; set; }
public AwayTeamForm awayTeamForm { get; set; }
}
public class Head2head
{
public int draws { get; set; }
public int homeWins { get; set; }
public int awayWins { get; set; }
public double avgGolsH2H { get; set; }
}
public class EventPlayer
{
public string playerName { get; set; }
public string playerShortName { get; set; }
public string playerID { get; set; }
}
public class MatchEvent
{
public string eventName { get; set; }
public string eventType { get; set; }
public string eventTeam { get; set; }
public int eventTime { get; set; }
public EventPlayer eventPlayer { get; set; }
public object eventSubIn { get; set; }
public object eventSubOut { get; set; }
public bool eventHomeTeam { get; set; }
}
public class RootObject : List<RootObject>
{
public string timeLive { get; set; }
public string halfTimeScore { get; set; }
public object fullTimeScore { get; set; }
public object firstTeamToScore { get; set; }
public HomeTeamInfo homeTeamInfo { get; set; }
public AwayTeamInfo awayTeamInfo { get; set; }
public Head2head head2head { get; set; }
public List<MatchEvent> matchEvents { get; set; }
}
Now you need to Deserialize json to the class.
RootObject myCShartData = new JavaScriptSerializer().Deserialize<RootObject>(json);
Now you are ready to bind gridview using myCShartData variable
I hope you will be helpful

Related

Deserialize Inconsistent JSON

I'm trying to create a basic Xamarin Forms app that can list available gateways on my PFsense firewall, Show the available gateway and change this to another gateway to route through if required. The problem I have is I cannot deserialize the JSON in C# because each object has a different object name:
{
"status": "ok",
"code": 200,
"return": 0,
"message": "Success",
"data": {
"GW_WAN_1": {
"interface": "hn0",
"gateway": "192.168.0.1",
"name": "GW_WAN_1",
"weight": "1",
"ipprotocol": "inet",
"interval": "500",
"time_period": "60000",
"alert_interval": "1000",
"descr": "Interface wan Gateway",
"data_payload": "1",
"latencylow": "200",
"latencyhigh": "500",
"losslow": "10",
"losshigh": "20",
"loss_interval": "2000",
"monitor": "192.168.0.1",
"friendlyiface": "wan",
"friendlyifdescr": "RED",
"isdefaultgw": true,
"attribute": 0,
"tiername": "Default (IPv4)"
},
"INT1_DHCP6": {
"dynamic": true,
"ipprotocol": "inet6",
"gateway": "fe80::1af1:45ff:fe90:4b13",
"interface": "hn0",
"friendlyiface": "wan",
"friendlyifdescr": "RED",
"name": "INT1_DHCP6",
"attribute": "system",
"isdefaultgw": true,
"monitor": "fe80::1af1:45ff:fe90:4b13",
"descr": "Interface RED_DHCP6 Gateway",
"tiername": ""
},
"VPN_EUR_1": {
"interface": "ovpns1",
"gateway": "192.168.1.2",
"name": "VPN_EUR_1",
"weight": "1",
"ipprotocol": "inet",
"interval": "500",
"time_period": "60000",
"alert_interval": "1000",
"descr": "Interface VPN_EUR_1 Gateway",
"data_payload": "1",
"latencylow": "200",
"latencyhigh": "500",
"losslow": "10",
"losshigh": "20",
"loss_interval": "2000",
"dynamic": true,
"monitor": "192.168.1.2",
"friendlyiface": "opt4",
"friendlyifdescr": "VPN_EUR_1",
"attribute": 1,
"tiername": ""
},
"Null4": {
"name": "Null4",
"interface": "lo0",
"ipprotocol": "inet",
"gateway": "127.0.0.1",
"attribute": "system",
"tiername": ""
},
"Null6": {
"name": "Null6",
"interface": "lo0",
"ipprotocol": "inet6",
"gateway": "::1",
"attribute": "system",
"tiername": ""
},
"VPN_EUR_1V6": {
"dynamic": false,
"ipprotocol": "inet6",
"gateway": null,
"interface": "ovpns1",
"friendlyiface": "opt4",
"friendlyifdescr": "VPN_EUR_1",
"name": "VPN_EUR_1V6",
"attribute": "system",
"descr": "Interface VPN_EUR_1V6 Gateway",
"tiername": ""
}
}
}
Here's how I've gone about trying to deserialize:
string authHeader = Constants.AUTH_HEADER;
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", authHeader);
var response = await client.GetAsync(Constants.GATEWAY);
var json = await response.Content.ReadAsStringAsync();
var gateways = JsonConvert.DeserializeObject<Data>(json);
The C# Object (Generated using json to C# converter):
public class GW_WAN_1
{
public string #interface { get; set; }
public string gateway { get; set; }
public string name { get; set; }
public string weight { get; set; }
public string ipprotocol { get; set; }
public string interval { get; set; }
public string time_period { get; set; }
public string alert_interval { get; set; }
public string descr { get; set; }
public string data_payload { get; set; }
public string latencylow { get; set; }
public string latencyhigh { get; set; }
public string losslow { get; set; }
public string losshigh { get; set; }
public string loss_interval { get; set; }
public string monitor { get; set; }
public string friendlyiface { get; set; }
public string friendlyifdescr { get; set; }
public bool isdefaultgw { get; set; }
public int attribute { get; set; }
public string tiername { get; set; }
}
public class INT1_DHCP6
{
public bool dynamic { get; set; }
public string ipprotocol { get; set; }
public string gateway { get; set; }
public string #interface { get; set; }
public string friendlyiface { get; set; }
public string friendlyifdescr { get; set; }
public string name { get; set; }
public string attribute { get; set; }
public bool isdefaultgw { get; set; }
public string monitor { get; set; }
public string descr { get; set; }
public string tiername { get; set; }
}
public class VPN_EUR_1
{
public string #interface { get; set; }
public string gateway { get; set; }
public string name { get; set; }
public string weight { get; set; }
public string ipprotocol { get; set; }
public string interval { get; set; }
public string time_period { get; set; }
public string alert_interval { get; set; }
public string descr { get; set; }
public string data_payload { get; set; }
public string latencylow { get; set; }
public string latencyhigh { get; set; }
public string losslow { get; set; }
public string losshigh { get; set; }
public string loss_interval { get; set; }
public bool dynamic { get; set; }
public string monitor { get; set; }
public string friendlyiface { get; set; }
public string friendlyifdescr { get; set; }
public int attribute { get; set; }
public string tiername { get; set; }
}
public class Null4
{
public string name { get; set; }
public string #interface { get; set; }
public string ipprotocol { get; set; }
public string gateway { get; set; }
public string attribute { get; set; }
public string tiername { get; set; }
}
public class Null6
{
public string name { get; set; }
public string #interface { get; set; }
public string ipprotocol { get; set; }
public string gateway { get; set; }
public string attribute { get; set; }
public string tiername { get; set; }
}
public class VPN_EUR_1V6
{
public bool dynamic { get; set; }
public string ipprotocol { get; set; }
public object gateway { get; set; }
public string #interface { get; set; }
public string friendlyiface { get; set; }
public string friendlyifdescr { get; set; }
public string name { get; set; }
public string attribute { get; set; }
public string descr { get; set; }
public string tiername { get; set; }
}
public class Data
{
public GW_WAN_1 GW_WAN { get; set; }
public INT1_DHCP6 INT1_DHCP6 { get; set; }
public VPN_EUR_1 VPN_EUR_1 { get; set; }
public Null4 Null4 { get; set; }
public Null6 Null6 { get; set; }
public VPN_EUR_1V6 VPN_NL_VPNV6 { get; set; }
}
public class Root
{
public string status { get; set; }
public int code { get; set; }
public int #return { get; set; }
public string message { get; set; }
public Data data { get; set; }
}
The problem is in the gateways variable, all of the properties are null. I think because of how the JSON is structured in the response, it might not be possible in C#, but perhaps there's another way of going about it?
The API for the firewall is here:
https://github.com/jaredhendrickson13/pfsense-api
Thanks

Querying Json with Linq, Cannot access child value

I am new to C# with JSON. I would like to select with Nvidia API, the "featuredProduct" part, but I have an error
Cannot access child value on Newtonsoft.Json.Linq.JProperty.
This code works for the "searchedProducts" part.
Can you explain to me why?
const string url = "";
const int refresh = 3000;
string json = getGpuFromNvidia(url);
var jsonParse = JObject.Parse(json);
var result = jsonParse["searchedProducts"]["featuredProduct"]
.Where(n => n["isFounderEdition"].Value<bool>() == true)
.Select(p => new CarteGraphique
{
displayName = (string)p["displayName"],
prdStatus = (string)p["prdStatus"],
directPurchaseLink = (string)p["retailers"][0]["directPurchaseLink"]
})
.ToList();
I tested this code in VS
string json = ...your code
var jsonObj = JsonConvert.DeserializeObject<NvidiaRoot>(json);
var result = jsonObj.searchedProducts.productDetails
.Where(n => n.isFounderEdition)
.Select(p => new
{
displayName = p.displayName,
prdStatus = p.prdStatus,
directPurchaseLink = p.retailers[0].directPurchaseLink
})
.ToList();
OUTPUT
[
{
"displayName": "NVIDIA RTX 3090",
"prdStatus": "out_of_stock",
"directPurchaseLink": "https://www.ldlc.com/fiche/PB89455870.html"
},
{
"displayName": "NVIDIA RTX 3070",
"prdStatus": "out_of_stock",
"directPurchaseLink": "https://www.ldlc.com/fiche/PB74221588.html"
},
{
"displayName": "NVIDIA RTX 3060 Ti",
"prdStatus": "out_of_stock",
"directPurchaseLink": "https://www.ldlc.com/fiche/PB54012144.html"
},
{
"displayName": "NVIDIA RTX 3070 Ti",
"prdStatus": "out_of_stock",
"directPurchaseLink": null
},
{
"displayName": "NVIDIA RTX 3080 Ti",
"prdStatus": "out_of_stock",
"directPurchaseLink": null
}
]
UPDATE
if you need just a feature product
var featuredProduct = jsonObj.searchedProducts.featuredProduct;
var result = new
{
displayName = featuredProduct.displayName,
prdStatus = featuredProduct.prdStatus,
directPurchaseLink = featuredProduct.retailers[0].directPurchaseLink
};
Short OUTPUT
{
"displayName": "NVIDIA RTX 3080",
"prdStatus": "out_of_stock",
"directPurchaseLink": "https://www.ldlc.com/fiche/PB15921567.html"
}
Full OUTPUT
var result = jsonObj.searchedProducts.featuredProduct;
{
"displayName": "NVIDIA RTX 3080",
"totalCount": 1,
"productID": 30045,
"imageURL": "https://assets.nvidia.partners/images/png/nvidia-geforce-rtx-3080.png",
"productTitle": "NVIDIA GEFORCE RTX 3080",
"digitialRiverID": "",
"productSKU": "NVGFT080",
"productUPC": "NVGFT080_FR",
"productUPCOriginal": "NVGFT080",
"productPrice": "€719.00",
"productAvailable": false,
"productRating": null,
"customerReviewCount": null,
"isFounderEdition": true,
"isFeaturedProduct": true,
"certified": false,
"manufacturer": "NVIDIA",
"locale": "FR",
"isFeaturedProdcutFoundInSecondSearch": false,
"category": "GPU",
"gpu": "RTX 3080",
"purchaseOption": "",
"prdStatus": "out_of_stock",
"minShipDays": null,
"maxShipDays": null,
"shipInfo": null,
"isOffer": false,
"offerText": "",
"retailers": [
{
"productId": 30045,
"productTitle": "NVIDIA GEFORCE RTX 3080",
"logoUrl": "https://assets.nvidia.partners/logos/geforce/retailer-ldlc.png",
"isAvailable": true,
"salePrice": "719.00",
"directPurchaseLink": "https://www.ldlc.com/fiche/PB15921567.html",
"purchaseLink": "https://www.ldlc.com/fiche/PB15921567.html",
"hasOffer": false,
"offerText": null,
"partnerId": "45",
"storeId": "45",
"upc": "NVGFT080_FR",
"sku": "NVGFT080",
"stock": 0,
"retailerName": "https://www.ldlc.com",
"type": 80
}
],
"productInfo": [
{
"name": "cooling_system",
"value": "Fan"
},
{
"name": "gpu_boost_clock_speed",
"value": "1.71 GHz"
},
{
"name": "gpu_memory_size",
"value": "10 GB"
}
],
"compareProductInfo": [
{
"name": "cooling_system",
"value": "Fan"
},
{
"name": "gpu_clock_speed",
"value": "1.44 GHz"
},
{
"name": "gpu_boost_clock_speed",
"value": "1.71 GHz"
},
{
"name": "gpu_memory_size",
"value": "10 GB"
}
]
}
classes
public class NvidiaRoot
{
public object categories { get; set; }
public List<Filter> filters { get; set; }
public object filterGroups { get; set; }
public object search { get; set; }
public string version { get; set; }
public List<Sort> sort { get; set; }
public Pagination pagination { get; set; }
public SearchedProducts searchedProducts { get; set; }
public Disclaimer disclaimer { get; set; }
}
public class FilterValue
{
public string dispValue { get; set; }
public object dispValueDesription { get; set; }
public object groupType { get; set; }
public int units { get; set; }
public bool #checked { get; set; }
public object imageURL { get; set; }
public bool isValidate { get; set; }
}
public class Filter
{
public string displayName { get; set; }
public string filterField { get; set; }
public string displayMaxValues { get; set; }
public string fieldType { get; set; }
public int? selectedMinRangeVal { get; set; }
public int? selectedMaxRangeVal { get; set; }
public int? defaultMinRangeVal { get; set; }
public int? defaultMaxRangeVal { get; set; }
public string unitsOfMeasure { get; set; }
public bool #checked { get; set; }
public object units { get; set; }
public List<FilterValue> filterValues { get; set; }
public string dataType { get; set; }
public bool showCount { get; set; }
public int filterDisplayOrder { get; set; }
}
public class Sort
{
public string displayName { get; set; }
public string value { get; set; }
public bool selected { get; set; }
}
public class Pagination
{
public int page { get; set; }
public int limit { get; set; }
public int totalRecords { get; set; }
public bool featuredProductIncludedInCount { get; set; }
}
public class Retailer
{
public int productId { get; set; }
public string productTitle { get; set; }
public string logoUrl { get; set; }
public bool isAvailable { get; set; }
public string salePrice { get; set; }
public string directPurchaseLink { get; set; }
public string purchaseLink { get; set; }
public bool hasOffer { get; set; }
public object offerText { get; set; }
public string partnerId { get; set; }
public string storeId { get; set; }
public string upc { get; set; }
public string sku { get; set; }
public int stock { get; set; }
public string retailerName { get; set; }
public int type { get; set; }
}
public class ProductInfo
{
public string name { get; set; }
public string value { get; set; }
}
public class CompareProductInfo
{
public string name { get; set; }
public string value { get; set; }
}
public class FeaturedProduct
{
public string displayName { get; set; }
public int totalCount { get; set; }
public int productID { get; set; }
public string imageURL { get; set; }
public string productTitle { get; set; }
public string digitialRiverID { get; set; }
public string productSKU { get; set; }
public string productUPC { get; set; }
public string productUPCOriginal { get; set; }
public string productPrice { get; set; }
public bool productAvailable { get; set; }
public object productRating { get; set; }
public object customerReviewCount { get; set; }
public bool isFounderEdition { get; set; }
public bool isFeaturedProduct { get; set; }
public bool certified { get; set; }
public string manufacturer { get; set; }
public string locale { get; set; }
public bool isFeaturedProdcutFoundInSecondSearch { get; set; }
public string category { get; set; }
public string gpu { get; set; }
public string purchaseOption { get; set; }
public string prdStatus { get; set; }
public object minShipDays { get; set; }
public object maxShipDays { get; set; }
public object shipInfo { get; set; }
public bool isOffer { get; set; }
public string offerText { get; set; }
public List<Retailer> retailers { get; set; }
public List<ProductInfo> productInfo { get; set; }
public List<CompareProductInfo> compareProductInfo { get; set; }
}
public class ProductDetail
{
public string displayName { get; set; }
public int totalCount { get; set; }
public int productID { get; set; }
public string imageURL { get; set; }
public string productTitle { get; set; }
public string digitialRiverID { get; set; }
public string productSKU { get; set; }
public string productUPC { get; set; }
public string productUPCOriginal { get; set; }
public string productPrice { get; set; }
public bool productAvailable { get; set; }
public object productRating { get; set; }
public object customerReviewCount { get; set; }
public bool isFounderEdition { get; set; }
public bool isFeaturedProduct { get; set; }
public bool certified { get; set; }
public string manufacturer { get; set; }
public string locale { get; set; }
public bool isFeaturedProdcutFoundInSecondSearch { get; set; }
public string category { get; set; }
public string gpu { get; set; }
public string purchaseOption { get; set; }
public string prdStatus { get; set; }
public object minShipDays { get; set; }
public object maxShipDays { get; set; }
public object shipInfo { get; set; }
public bool isOffer { get; set; }
public string offerText { get; set; }
public List<Retailer> retailers { get; set; }
public List<ProductInfo> productInfo { get; set; }
public List<CompareProductInfo> compareProductInfo { get; set; }
}
public class SearchedProducts
{
public int totalProducts { get; set; }
public bool featuredProductIncludedInCount { get; set; }
public bool featuredProductsFlag { get; set; }
public FeaturedProduct featuredProduct { get; set; }
public List<ProductDetail> productDetails { get; set; }
public List<object> suggestedProductDetails { get; set; }
}
public class Disclaimer
{
public string text { get; set; }
}
You can try the below code.
To get the Featured Product. Sample Working code Here
var jsonParse = JObject.Parse(json);
var featuredProduct = jsonParse["searchedProducts"]["featuredProduct"];
var f = new CarteGraphique
{
displayName = featuredProduct["displayName"].ToString(),
prdStatus = featuredProduct["prdStatus"].ToString(),
directPurchaseLink = featuredProduct["retailers"][0]["directPurchaseLink"].ToString()
};
Console.WriteLine("Featured Product Details : " + f.displayName + ", " + f.prdStatus + ", " + f.directPurchaseLink);

Value from deserialized JSON object is NULL

I am having some trouble getting a value from a deserialized JSON string.
Here is my JSON string:
{
"expand": "names,schema",
"startAt": 0,
"maxResults": 1,
"total": 151,
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"id": "10210",
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/issue/10210",
"key": "ITSD-202",
"fields": {
"statuscategorychangedate": "2021-01-25T20:12:11.922+0000",
"issuetype": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/issuetype/10003",
"id": "10003",
"description": "For customer support issues. Created by Jira Service Desk.",
"iconUrl": "https://xxxxxxxxxx.atlassian.net/secure/viewavatar?size=medium&avatarId=10308&avatarType=issuetype",
"name": "Support",
"subtask": false,
"avatarId": 10308
},
"timespent": null,
"customfield_10030": null,
"customfield_10031": {
"id": "1",
"name": "Time to resolution",
"_links": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/servicedeskapi/request/10210/sla/1"
},
"completedCycles": [],
"ongoingCycle": {
"startTime": {
"iso8601": "2021-01-25T20:12:11+0000",
"jira": "2021-01-25T20:12:11.592+0000",
"friendly": "Yesterday 08:12",
"epochMillis": 1611605531592
},
"breachTime": {
"iso8601": "2021-02-11T14:30:00+0000",
"jira": "2021-02-11T14:30:00.000+0000",
"friendly": "11/Feb/21 02:30",
"epochMillis": 1613053800000
},
"breached": false,
"paused": false,
"withinCalendarHours": false,
"goalDuration": {
"millis": 432000000,
"friendly": "120h"
},
"elapsedTime": {
"millis": 0,
"friendly": "0m"
},
"remainingTime": {
"millis": 432000000,
"friendly": "120h"
}
}
},
"project": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/project/10000",
"id": "10000",
"key": "ITSD",
"name": "Customer Service Desk",
"projectTypeKey": "service_desk",
"simplified": false,
"avatarUrls": {
"48x48": "https://xxxxxxxxxx.atlassian.net/secure/projectavatar?pid=10000&avatarId=10412",
"24x24": "https://xxxxxxxxxx.atlassian.net/secure/projectavatar?size=small&s=small&pid=10000&avatarId=10412",
"16x16": "https://xxxxxxxxxx.atlassian.net/secure/projectavatar?size=xsmall&s=xsmall&pid=10000&avatarId=10412",
"32x32": "https://xxxxxxxxxx.atlassian.net/secure/projectavatar?size=medium&s=medium&pid=10000&avatarId=10412"
}
},
"customfield_10032": {
"id": "2",
"name": "Time to first response",
"_links": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/servicedeskapi/request/10210/sla/2"
},
"completedCycles": [],
"ongoingCycle": {
"startTime": {
"iso8601": "2021-01-25T20:12:11+0000",
"jira": "2021-01-25T20:12:11.592+0000",
"friendly": "Yesterday 08:12",
"epochMillis": 1611605531592
},
"breachTime": {
"iso8601": "2021-01-26T12:30:00+0000",
"jira": "2021-01-26T12:30:00.000+0000",
"friendly": "Today 12:30",
"epochMillis": 1611664200000
},
"breached": false,
"paused": false,
"withinCalendarHours": false,
"goalDuration": {
"millis": 14400000,
"friendly": "4h"
},
"elapsedTime": {
"millis": 0,
"friendly": "0m"
},
"remainingTime": {
"millis": 14400000,
"friendly": "4h"
}
}
},
"fixVersions": [],
"customfield_10034": {
"languageCode": "en",
"displayName": "English"
},
"resolution": null,
"customfield_10037": null,
"customfield_10027": null,
"customfield_10028": null,
"customfield_10029": null,
"resolutiondate": null,
"workratio": -1,
"lastViewed": "2021-01-25T20:12:11.936+0000",
"watches": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/issue/ITSD-202/watchers",
"watchCount": 1,
"isWatching": true
},
"created": "2021-01-25T20:12:11.592+0000",
"customfield_10020": null,
"customfield_10021": null,
"customfield_10022": null,
"customfield_10023": null,
"priority": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/priority/3",
"iconUrl": "https://xxxxxxxxxx.atlassian.net/images/icons/priorities/medium.svg",
"name": "Medium",
"id": "3"
},
"customfield_10024": null,
"customfield_10025": null,
"labels": [],
"customfield_10026": [],
"customfield_10016": null,
"customfield_10017": null,
"customfield_10018": {
"hasEpicLinkFieldDependency": false,
"showField": false,
"nonEditableReason": {
"reason": "PLUGIN_LICENSE_ERROR",
"message": "The Parent Link is only available to Jira Premium users."
}
},
"customfield_10019": "0|i0013b:",
"timeestimate": null,
"versions": [],
"assignee": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/user?accountId=12345678912345678912345",
"accountId": "12345678912345678912345",
"emailAddress": "first.last#xxxxxxxxxx.co.uk",
"avatarUrls": {
"48x48": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png",
"24x24": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png",
"16x16": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png",
"32x32": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png"
},
"displayName": "First Last",
"active": true,
"timeZone": "Europe/London",
"accountType": "atlassian"
},
"updated": "2021-01-25T20:12:14.321+0000",
"status": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/status/10001",
"description": "This was auto-generated by Jira Service Desk during workflow import",
"iconUrl": "https://xxxxxxxxxx.atlassian.net/images/icons/status_generic.gif",
"name": "Waiting for support",
"id": "10001",
"statusCategory": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
},
"components": [],
"customfield_10050": null,
"customfield_10051": null,
"timeoriginalestimate": null,
"customfield_10052": null,
"customfield_10053": null,
"description": null,
"customfield_10010": null,
"customfield_10014": null,
"customfield_10015": null,
"customfield_10005": null,
"customfield_10049": null,
"customfield_10006": null,
"customfield_10007": null,
"security": null,
"customfield_10008": null,
"customfield_10009": null,
"summary": "Barry Test",
"creator": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/user?accountId=12345678912345678912345",
"accountId": "12345678912345678912345",
"emailAddress": "first.last#xxxxxxxxxx.co.uk",
"avatarUrls": {
"48x48": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png",
"24x24": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png",
"16x16": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png",
"32x32": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png"
},
"displayName": "First Last",
"active": true,
"timeZone": "Europe/London",
"accountType": "atlassian"
},
"customfield_10040": null,
"customfield_10041": null,
"customfield_10042": null,
"customfield_10043": null,
"reporter": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/api/3/user?accountId=12345678912345678912345",
"accountId": "12345678912345678912345",
"emailAddress": "first.last#xxxxxxxxxx.co.uk",
"avatarUrls": {
"48x48": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png",
"24x24": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png",
"16x16": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png",
"32x32": "https://secure.gravatar.com/avatar/2758e009bbe7f2348bfdf52d653b6a2b?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FBE-1.png"
},
"displayName": "First Last",
"active": true,
"timeZone": "Europe/London",
"accountType": "atlassian"
},
"customfield_10044": null,
"customfield_10000": "{}",
"customfield_10001": null,
"customfield_10045": null,
"customfield_10046": null,
"customfield_10002": [
{
"id": "4",
"name": "xxxxxxxxxx.co.uk",
"_links": {
"self": "https://xxxxxxxxxx.atlassian.net/rest/servicedeskapi/organization/4"
}
}
],
"customfield_10003": null,
"customfield_10047": null,
"customfield_10048": null,
"customfield_10004": null,
"customfield_10038": null,
"customfield_10039": null,
"environment": null,
"duedate": null,
"progress": {
"progress": 0,
"total": 0
}
}
}
]
}
And this is how I am deseriazling it and trying to return the values.
var root = JsonConvert.DeserializeObject<Rootobject2>(response.Content);
foreach (var issue in root.issues)
{
string id = issue.id.ToString();
string key = issue.key.ToString();
string summary = issue.fields.summary.ToString();
string creatoremail = issue.fields.creator.emailAddress.ToString();
public class Rootobject2
{
public string expand { get; set; }
public int startAt { get; set; }
public int maxResults { get; set; }
public int total { get; set; }
public Issue[] issues { get; set; }
}
public class Issue
{
public string expand { get; set; }
public string id { get; set; }
public string self { get; set; }
public string key { get; set; }
public Fields fields { get; set; }
}
public class Fields
{
public DateTime statuscategorychangedate { get; set; }
public Issuetype issuetype { get; set; }
public int? timespent { get; set; }
public object customfield_10030 { get; set; }
public Customfield_10031 customfield_10031 { get; set; }
public Project project { get; set; }
public Customfield_10032 customfield_10032 { get; set; }
public object[] fixVersions { get; set; }
public Customfield_10034 customfield_10034 { get; set; }
public Resolution resolution { get; set; }
public object customfield_10037 { get; set; }
public object customfield_10027 { get; set; }
public object customfield_10028 { get; set; }
public object customfield_10029 { get; set; }
public DateTime? resolutiondate { get; set; }
public int workratio { get; set; }
public DateTime? lastViewed { get; set; }
public Watches watches { get; set; }
public DateTime created { get; set; }
public object customfield_10020 { get; set; }
public object customfield_10021 { get; set; }
public object customfield_10022 { get; set; }
public Priority priority { get; set; }
public object customfield_10023 { get; set; }
public DateTime? customfield_10024 { get; set; }
public string customfield_10025 { get; set; }
public object[] customfield_10026 { get; set; }
public object[] labels { get; set; }
public object customfield_10016 { get; set; }
public object customfield_10017 { get; set; }
public Customfield_10018 customfield_10018 { get; set; }
public string customfield_10019 { get; set; }
public int? timeestimate { get; set; }
public object[] versions { get; set; }
public Assignee assignee { get; set; }
public DateTime updated { get; set; }
public Status status { get; set; }
public Component[] components { get; set; }
public object customfield_10050 { get; set; }
public object customfield_10051 { get; set; }
public object timeoriginalestimate { get; set; }
public object customfield_10052 { get; set; }
public object customfield_10053 { get; set; }
public Description description { get; set; }
public Customfield_10010 customfield_10010 { get; set; }
public object customfield_10014 { get; set; }
public object customfield_10015 { get; set; }
public object customfield_10005 { get; set; }
public object customfield_10049 { get; set; }
public object customfield_10006 { get; set; }
public object customfield_10007 { get; set; }
public object security { get; set; }
public object customfield_10008 { get; set; }
public object customfield_10009 { get; set; }
public string summary { get; set; }
public Creator creator { get; set; }
public object customfield_10040 { get; set; }
public object customfield_10041 { get; set; }
public object customfield_10042 { get; set; }
public object customfield_10043 { get; set; }
public Reporter reporter { get; set; }
public string customfield_10000 { get; set; }
public object customfield_10044 { get; set; }
public object customfield_10045 { get; set; }
public object customfield_10001 { get; set; }
public object customfield_10046 { get; set; }
public Customfield_10002[] customfield_10002 { get; set; }
public object customfield_10047 { get; set; }
public object customfield_10003 { get; set; }
public object customfield_10048 { get; set; }
public object customfield_10004 { get; set; }
public object customfield_10038 { get; set; }
public object customfield_10039 { get; set; }
public object environment { get; set; }
public object duedate { get; set; }
public Progress progress { get; set; }
}
(Dictionary created by doing paste special values in Visual Studio)
The issue I am seeing, I get "Object reference not set to an instance of an object." on
foreach (var issue in root.issues)
Any help greatly appreciated
Your class for deserialization should look something like this
public class Issuetype {
public string self { get; set; }
public string id { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public bool subtask { get; set; }
public int avatarId { get; set; }
}
public class Links {
public string self { get; set; }
}
public class StartTime {
public DateTime iso8601 { get; set; }
public DateTime jira { get; set; }
public string friendly { get; set; }
public long epochMillis { get; set; }
}
public class BreachTime {
public DateTime iso8601 { get; set; }
public DateTime jira { get; set; }
public string friendly { get; set; }
public long epochMillis { get; set; }
}
public class GoalDuration {
public int millis { get; set; }
public string friendly { get; set; }
}
public class ElapsedTime {
public int millis { get; set; }
public string friendly { get; set; }
}
public class RemainingTime {
public int millis { get; set; }
public string friendly { get; set; }
}
public class OngoingCycle {
public StartTime startTime { get; set; }
public BreachTime breachTime { get; set; }
public bool breached { get; set; }
public bool paused { get; set; }
public bool withinCalendarHours { get; set; }
public GoalDuration goalDuration { get; set; }
public ElapsedTime elapsedTime { get; set; }
public RemainingTime remainingTime { get; set; }
}
public class Customfield10031 {
public string id { get; set; }
public string name { get; set; }
public Links _links { get; set; }
public List<object> completedCycles { get; set; }
public OngoingCycle ongoingCycle { get; set; }
}
public class AvatarUrls {
public string _48x48 { get; set; }
public string _24x24 { get; set; }
public string _16x16 { get; set; }
public string _32x32 { get; set; }
}
public class Project {
public string self { get; set; }
public string id { get; set; }
public string key { get; set; }
public string name { get; set; }
public string projectTypeKey { get; set; }
public bool simplified { get; set; }
public AvatarUrls avatarUrls { get; set; }
}
public class Customfield10032 {
public string id { get; set; }
public string name { get; set; }
public Links _links { get; set; }
public List<object> completedCycles { get; set; }
public OngoingCycle ongoingCycle { get; set; }
}
public class Customfield10034 {
public string languageCode { get; set; }
public string displayName { get; set; }
}
public class Watches {
public string self { get; set; }
public int watchCount { get; set; }
public bool isWatching { get; set; }
}
public class Priority {
public string self { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
}
public class NonEditableReason {
public string reason { get; set; }
public string message { get; set; }
}
public class Customfield10018 {
public bool hasEpicLinkFieldDependency { get; set; }
public bool showField { get; set; }
public NonEditableReason nonEditableReason { get; set; }
}
public class Assignee {
public string self { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
public string accountType { get; set; }
}
public class StatusCategory {
public string self { get; set; }
public int id { get; set; }
public string key { get; set; }
public string colorName { get; set; }
public string name { get; set; }
}
public class Status {
public string self { get; set; }
public string description { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public string id { get; set; }
public StatusCategory statusCategory { get; set; }
}
public class Creator {
public string self { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
public string accountType { get; set; }
}
public class Reporter {
public string self { get; set; }
public string accountId { get; set; }
public string emailAddress { get; set; }
public AvatarUrls avatarUrls { get; set; }
public string displayName { get; set; }
public bool active { get; set; }
public string timeZone { get; set; }
public string accountType { get; set; }
}
public class Customfield10002 {
public string id { get; set; }
public string name { get; set; }
public Links _links { get; set; }
}
public class Progress {
public int progress { get; set; }
public int total { get; set; }
}
public class Fields {
public DateTime statuscategorychangedate { get; set; }
public Issuetype issuetype { get; set; }
public object timespent { get; set; }
public object customfield_10030 { get; set; }
public Customfield10031 customfield_10031 { get; set; }
public Project project { get; set; }
public Customfield10032 customfield_10032 { get; set; }
public List<object> fixVersions { get; set; }
public Customfield10034 customfield_10034 { get; set; }
public object resolution { get; set; }
public object customfield_10037 { get; set; }
public object customfield_10027 { get; set; }
public object customfield_10028 { get; set; }
public object customfield_10029 { get; set; }
public object resolutiondate { get; set; }
public int workratio { get; set; }
public DateTime lastViewed { get; set; }
public Watches watches { get; set; }
public DateTime created { get; set; }
public object customfield_10020 { get; set; }
public object customfield_10021 { get; set; }
public object customfield_10022 { get; set; }
public object customfield_10023 { get; set; }
public Priority priority { get; set; }
public object customfield_10024 { get; set; }
public object customfield_10025 { get; set; }
public List<object> labels { get; set; }
public List<object> customfield_10026 { get; set; }
public object customfield_10016 { get; set; }
public object customfield_10017 { get; set; }
public Customfield10018 customfield_10018 { get; set; }
public string customfield_10019 { get; set; }
public object timeestimate { get; set; }
public List<object> versions { get; set; }
public Assignee assignee { get; set; }
public DateTime updated { get; set; }
public Status status { get; set; }
public List<object> components { get; set; }
public object customfield_10050 { get; set; }
public object customfield_10051 { get; set; }
public object timeoriginalestimate { get; set; }
public object customfield_10052 { get; set; }
public object customfield_10053 { get; set; }
public object description { get; set; }
public object customfield_10010 { get; set; }
public object customfield_10014 { get; set; }
public object customfield_10015 { get; set; }
public object customfield_10005 { get; set; }
public object customfield_10049 { get; set; }
public object customfield_10006 { get; set; }
public object customfield_10007 { get; set; }
public object security { get; set; }
public object customfield_10008 { get; set; }
public object customfield_10009 { get; set; }
public string summary { get; set; }
public Creator creator { get; set; }
public object customfield_10040 { get; set; }
public object customfield_10041 { get; set; }
public object customfield_10042 { get; set; }
public object customfield_10043 { get; set; }
public Reporter reporter { get; set; }
public object customfield_10044 { get; set; }
public string customfield_10000 { get; set; }
public object customfield_10001 { get; set; }
public object customfield_10045 { get; set; }
public object customfield_10046 { get; set; }
public List<Customfield10002> customfield_10002 { get; set; }
public object customfield_10003 { get; set; }
public object customfield_10047 { get; set; }
public object customfield_10048 { get; set; }
public object customfield_10004 { get; set; }
public object customfield_10038 { get; set; }
public object customfield_10039 { get; set; }
public object environment { get; set; }
public object duedate { get; set; }
public Progress progress { get; set; }
}
public class Issue {
public string expand { get; set; }
public string id { get; set; }
public string self { get; set; }
public string key { get; set; }
public Fields fields { get; set; }
}
public class Root {
public string expand { get; set; }
public int startAt { get; set; }
public int maxResults { get; set; }
public int total { get; set; }
public List<Issue> issues { get; set; }
}
and you'd deserialize like this
Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
Always try to see references when creting json objects, I use this page
As commmented below, this would be the main:
using Newtonsoft.Json;
using System;
using System.IO;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Root myDeserializedClass = JsonConvert.DeserializeObject<Root> (File.ReadAllText(#"response.json"));
foreach (var issue in myDeserializedClass.issues)
{
string id = issue.id.ToString();
string key = issue.key.ToString();
string summary = issue.fields.summary.ToString();
string creatoremail = issue.fields.creator.emailAddress.ToString();
}
}
}
}
I think the problem you're having might be the way you're writting your foreach? I mean the code seems to be lacking something, but perhaps you shortened it.

Deserialize JSON to List

I have this Json:
{
"trades": [
{
"id": "4004",
"instrument": "EUR_USD",
"price": "1.08938",
"openTime": "2020-02-26T12:15:32.309973340Z",
"initialUnits": "1",
"initialMarginRequired": "0.0363",
"state": "OPEN",
"currentUnits": "1",
"realizedPL": "0.0000",
"financing": "0.0000",
"dividendAdjustment": "0.0000",
"unrealizedPL": "-0.0026",
"marginUsed": "0.0362",
"takeProfitOrder": {
"id": "4005",
"createTime": "2020-02-26T12:15:32.309973340Z",
"type": "TAKE_PROFIT",
"tradeID": "4004",
"price": "1.09099",
"timeInForce": "GTC",
"triggerCondition": "DEFAULT",
"state": "PENDING"
}
}
],
"lastTransactionID": "4010"
}
And Classes:
public class TakeProfitOrder
{
public string id { get; set; }
public string createTime { get; set; }
public string type { get; set; }
public string tradeID { get; set; }
public string price { get; set; }
public string timeInForce { get; set; }
public string triggerCondition { get; set; }
public string state { get; set; }
}
public class Trade
{
public string id { get; set; }
public string instrument { get; set; }
public string price { get; set; }
public string openTime { get; set; }
public string initialUnits { get; set; }
public string initialMarginRequired { get; set; }
public string state { get; set; }
public string currentUnits { get; set; }
public string realizedPL { get; set; }
public string financing { get; set; }
public string dividendAdjustment { get; set; }
public string unrealizedPL { get; set; }
public string marginUsed { get; set; }
public TakeProfitOrder takeProfitOrder { get; set; }
}
public class RootObject
{
public List<Trade> trades { get; set; }
public string lastTransactionID { get; set; }
}
I deserialize with :
var result = JsonConvert.DeserializeObject<RootObject>(Json);
var price = result.trades.Select(p => p.price).ToList();
price.ForEach(Console.WriteLine);
It works. I can access "price" in "trades", but I do not know how to access the "price" in "takeProfitOrder". I need the value of "price" from "takeProfitOrder" in to a list. I am sure it is something very simple but I cannot figure out how to do it, even after looking at some similar examples.
Can somebody please help me?
It's simple
result.trades.Select(p => p.takeProfitOrder.price)
You should understand better from this example
foreach (Trade trade in result.trades)
{
TakeProfitOrder takeProfitOrder = trade.takeProfitOrder;
Console.WriteLine(takeProfitOrder.price);
}

How can i extract PayPal Response C#

How can i extract this data in c#, in order to get all elements that i need:
{ "id": "PAY-6A414645MC669653MKPB2WCI", "create_time": "2014-07-14T10:03:53Z", "update_time": "2014-07-14T10:05:09Z", "intent": "sale", "payer": { "payment_method": "paypal", "payer_info": { "email": "severiano.testes#gmail.com", "first_name": "tester", "last_name": "tester", "payer_id": "MSQ6UB55W52N6", "shipping_address": { "line1": "1 Main Terrace", "line2": "", "city": "Wolverhampton", "country_code": "GB", "postal_code": "W12 4LQ", "state": "West Midlands" } } }, "transactions": [ { "amount": { "currency": "EUR", "total": "54.00", "details": { "subtotal": "54.00" } }, "description": "Transaction Description", "item_list": { "items": [ { "quantity": "1", "name": "Project Submission (featured)", "price": "54.00", "currency": "EUR", "sku": "64866" } ], "shipping_address": { "recipient_name": "tester tester", "line1": "1 Main Terrace", "line2": "", "city": "Wolverhampton", "country_code": "GB", "postal_code": "W12 4LQ", "state": "West Midlands" } }, "related_resources": [ { "sale": { "id": "4VV61663EL511901P", "create_time": "2014-07-14T10:03:53Z", "update_time": "2014-07-14T10:05:09Z", "amount": { "currency": "EUR", "total": "54.00" }, "state": "pending", "parent_payment": "PAY-6A414645MC669653MKPB2WCI", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/sale/4VV61663EL511901P", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/sale/4VV61663EL511901P/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-6A414645MC669653MKPB2WCI", "rel": "parent_payment", "method": "GET" } ] } } ] } ], "state": "pending", "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-6A414645MC669653MKPB2WCI", "rel": "self", "method": "GET" } ] }
I've tried to send to jquery function but not successfull.
I've tried this aswell:
JObject.Parse(HttpContext.Current.Items["ResponseJson"]).GetValue("id");
this works but only to one value, not all that i want
you have to declare class like
public class Rootobject
{
public string id { get; set; }
public DateTime create_time { get; set; }
public DateTime update_time { get; set; }
public string intent { get; set; }
public Payer payer { get; set; }
public Transaction[] transactions { get; set; }
public string state { get; set; }
public Link1[] links { get; set; }
}
public class Payer
{
public string payment_method { get; set; }
public Payer_Info payer_info { get; set; }
}
public class Payer_Info
{
public string email { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public string payer_id { get; set; }
public Shipping_Address shipping_address { get; set; }
}
public class Shipping_Address
{
public string line1 { get; set; }
public string line2 { get; set; }
public string city { get; set; }
public string country_code { get; set; }
public string postal_code { get; set; }
public string state { get; set; }
}
public class Transaction
{
public Amount amount { get; set; }
public string description { get; set; }
public Item_List item_list { get; set; }
public Related_Resources[] related_resources { get; set; }
}
public class Amount
{
public string currency { get; set; }
public string total { get; set; }
public Details details { get; set; }
}
public class Details
{
public string subtotal { get; set; }
}
public class Item_List
{
public Item[] items { get; set; }
public Shipping_Address1 shipping_address { get; set; }
}
public class Shipping_Address1
{
public string recipient_name { get; set; }
public string line1 { get; set; }
public string line2 { get; set; }
public string city { get; set; }
public string country_code { get; set; }
public string postal_code { get; set; }
public string state { get; set; }
}
public class Item
{
public string quantity { get; set; }
public string name { get; set; }
public string price { get; set; }
public string currency { get; set; }
public string sku { get; set; }
}
public class Related_Resources
{
public Sale sale { get; set; }
}
public class Sale
{
public string id { get; set; }
public DateTime create_time { get; set; }
public DateTime update_time { get; set; }
public Amount1 amount { get; set; }
public string state { get; set; }
public string parent_payment { get; set; }
public Link[] links { get; set; }
}
public class Amount1
{
public string currency { get; set; }
public string total { get; set; }
}
public class Link
{
public string href { get; set; }
public string rel { get; set; }
public string method { get; set; }
}
public class Link1
{
public string href { get; set; }
public string rel { get; set; }
public string method { get; set; }
}
Then you have to use using Newtonsoft.Json; for DeserializeObject like
var Data = JsonConvert.DeserializeObject<Rootobject>("your Json string");
you can access the property using Data
O/P looks like
You need to just make a mapping object and then deserialize the json
public class PaymentResponse
{
public string id { get; set; }
public DateTime create_time { get; set; }
public DateTime update_time { get; set; }
public string intent {get; set; }
public Payer payer{get; set; }
}
public class Payer
{
public string payment_method {get;set;}
public PayerInfo payer_info {get;set;}
}
public class PayerInfo
{
public string email { get; set; }
public string first_name { get; set; }
}
Don't have time to add all of the values but if you use a json parser so you can see the response easier. I prefer this one.
http://json.parser.online.fr/
Then simply deserialize the json response with the below
var paymentResponse = new JavaScriptSerializer().Deserialize<PaymentResponse>(jsonString);

Categories