且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

试图消耗SmartyStreets JSON与JSON.Net ..."无法反序列化JSON数组类型的组件和QUOT;

更新时间:2022-02-12 08:35:49

我preFER使用动态对象在这些情况下(无需创建丑类)

I prefer to use dynamic object in these cases (No need for creating ugly classes)

如:

dynamic jsonObj = JsonUtils.JsonObject.GetDynamicJsonObject(json);
foreach(var item in jsonObj)
{
    Console.WriteLine(item.delivery_line_1 + ", " + 
                      item.last_line + ", " +
                      item.metadata.county_name + ", " +
                      item.components.street_name + ", " + 
                      item.components.city_name  );

}

下面是动态JSON对象(只是复制和放大器;粘贴到您的项目)和的部分样品

Here is the source for Dynamic Json Object (just copy & paste to your project) and some samples

PS:这是更可读格式的JSON字符串

[
    {
        "input_index": 0,
        "candidate_index": 0,
        "delivery_line_1": "1600 Amphitheatre Pkwy",
        "last_line": "Mountain View CA 94043-1351",
        "delivery_point_barcode": "940431351000",
        "components": {
            "primary_number": "1600",
            "street_name": "Amphitheatre",
            "street_suffix": "Pkwy",
            "city_name": "Mountain View",
            "state_abbreviation": "CA",
            "zipcode": "94043",
            "plus4_code": "1351",
            "delivery_point": "00",
            "delivery_point_check_digit": "0"
        },
        "metadata": {
            "record_type": "S",
            "county_fips": "06085",
            "county_name": "Santa Clara",
            "carrier_route": "C058",
            "congressional_district": "14"
        },
        "analysis": {
            "dpv_match_code": "Y",
            "dpv_footnotes": "AABB",
            "dpv_cmra": "N",
            "dpv_vacant": "N",
            "ews_match": false,
            "footnotes": "N#"
        }
    }
]