Read property value from JSON string in ASP.Net MVC

on Jul 15, 2021 11:16 PM

I have get record from strip. 

How to set this value in ViewData. Please help me 

this is my return data 

"object": "list",
"data": [
"id": "card_JD7jCptsS0tiq9Unc44bHS",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": "22222",
"address_zip_check": "pass",
"brand": "Visa",
"country": "US",

"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2025,

"funding": "credit",
"last4": "4242", -- I have set only this field required.
"metadata": {},
"name": null,
"tokenization_method": null
"has_more": false,
"url": "/v1/customers/cus_Jmc7WhGNrkwoh5/sources"


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Jul 16, 2021 02:19 AM

Hi essitco.dotne...,

Check this example. Now please take its reference and correct your code.




public class Data
    public string id { get; set; }
    public string _object { get; set; }
    public object address_city { get; set; }
    public object address_country { get; set; }
    public object address_line1 { get; set; }
    public object address_line1_check { get; set; }
    public object address_line2 { get; set; }
    public object address_state { get; set; }
    public string address_zip { get; set; }
    public string address_zip_check { get; set; }
    public string brand { get; set; }
    public string country { get; set; }
    public string cvc_check { get; set; }
    public object dynamic_last4 { get; set; }
    public int exp_month { get; set; }
    public int exp_year { get; set; }
    public string funding { get; set; }
    public string last4 { get; set; }
    public object metadata { get; set; }
    public object name { get; set; }
    public object tokenization_method { get; set; }

public class Root
    public string _object { get; set; }
    public bool has_more { get; set; }
    public string url { get; set; }
    public List<Data> data { get; set; }


Public Class Data
    Public Property id As String
    Public Property _object As String
    Public Property address_city As Object
    Public Property address_country As Object
    Public Property address_line1 As Object
    Public Property address_line1_check As Object
    Public Property address_line2 As Object
    Public Property address_state As Object
    Public Property address_zip As String
    Public Property address_zip_check As String
    Public Property brand As String
    Public Property country As String
    Public Property cvc_check As String
    Public Property dynamic_last4 As Object
    Public Property exp_month As Integer
    Public Property exp_year As Integer
    Public Property funding As String
    Public Property last4 As String
    Public Property metadata As Object
    Public Property name As Object
    Public Property tokenization_method As Object
End Class

Public Class Root
    Public Property _object As String
    Public Property has_more As Boolean
    Public Property url As String
    Public Property data As List(Of Data)
End Class

Call to retrieve the data


// Reading the json string.
string json = System.IO.File.ReadAllText(Server.MapPath("~/json.json"));
Root result = Newtonsoft.Json.JsonConvert.DeserializeObject<Root>(json);
string last4 =[0].last4;


' Reading the json string.
Dim json As String = System.IO.File.ReadAllText(Server.MapPath("~/json.json"))
Dim result As Root = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Root)(json)
Dim last4 As String =