将JSON字符串转换为datatable或Array [英] convert JSON string to datatable Or Array

查看:120
本文介绍了将JSON字符串转换为datatable或Array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Friend



我会收到这种格式的字符串



Hello Friend

I'll get string in this format

{"region": {"span": {"latitude_delta": 0.053973589999998239, "longitude_delta": 0.088729300000011335}, "center": {"latitude": 37.781268949999998, "longitude": -122.42869970000001}}, "total": 11600, "businesses": [{"is_claimed": true, "rating": 4.0, "mobile_url": "http://m.yelp.com/biz/brendas-french-soul-food-san-francisco", "rating_img_url": "http://s3-media4.ak.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png", "review_count": 3601, "name": "Brenda's French Soul Food", "snippet_image_url": "http://s3-media4.ak.yelpcdn.com/photo/_wuD-DWVLO9cs8Y5GoAg_Q/ms.jpg", "rating_img_url_small": "http://s3-media4.ak.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png", "url": "http://www.yelp.com/biz/brendas-french-soul-food-san-francisco", "phone": "4153458100", "snippet_text": "Came here last night and the wait time was 30 minutes. Not too bad, but busy for a Weds. eve of course. \n\nThe specials were amazing. I was concerned that...", "image_url": "http://s3-media1.ak.yelpcdn.com/bphoto/9fpwRXGc886-i63VHKvudA/ms.jpg", "categories": [["Cajun/Creole", "cajun"], ["Breakfast \u0026 Brunch", "breakfast_brunch"], ["Soul Food", "soulfood"]], "display_phone": "+1-415-345-8100", "rating_img_url_large": "http://s3-media2.ak.yelpcdn.com/assets/2/www/img/ccf2b76faa2c/ico/stars/v1/stars_large_4.png", "id": "brendas-french-soul-food-san-francisco", "is_closed": false, "location": {"cross_streets": "Turk St \u0026 Eddy St", "city": "San Francisco", "display_address": ["652 Polk St", "(b/t Turk St \u0026 Eddy St)", "Tenderloin", "San Francisco, CA 94102"], "geo_accuracy": 8, "neighborhoods": ["Tenderloin"], "postal_code": "94102", "country_code": "US", "address": ["652 Polk St"], "coordinate": {"latitude": 37.782891800000002, "longitude": -122.4189883}, "state_code": "CA"}}, {"is_claimed": true, "rating": 4.0, "mobile_url": "http://m.yelp.com/biz/the-chairman-truck-san-francisco", "rating_img_url": "http://s3-media4.ak.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png", "review_count": 1023, "name": "The Chairman Truck", "snippet_image_url": "http://s3-media4.ak.yelpcdn.com/photo/uEyByBXuKs_s99zt1tWebg/ms.jpg", "rating_img_url_small": "http://s3-media4.ak.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png", "url": "http://www.yelp.com/biz/the-chairman-truck-san-francisco", "phone": "4158138800", "snippet_text": "The steamed bun is really delicious. I love the soft texture, and the fact that it's smaller means I get to try more!\nI had the pork belly and the coca cola...", "image_url": "http://s3-media2.ak.yelpcdn.com/bphoto/h_jIunZo5UIsVzO2bgggRw/ms.jpg", "categories": [["Chinese", "chinese"], ["Food Trucks", "foodtrucks"]], "display_phone": "+1-415-813-8800", "rating_img_url_large": "http://s3-media2.ak.yelpcdn.com/assets/2/www/img/ccf2b76faa2c/ico/stars/v1/stars_large_4.png", "id": "the-chairman-truck-san-francisco", "is_closed": false, "location": {"cross_streets": "Willow St \u0026 Ellis St", "city": "San Francisco", "display_address": ["670 Larkin St", "(b/t Willow St \u0026 Ellis St)", "Tenderloin", "San Francisco, CA 94109"], "geo_accuracy": 8, "neighborhoods": ["Tenderloin"], "postal_code": "94109", "country_code": "US", "address": ["670 Larkin St"], "coordinate": {"latitude": 37.784046500000002, "longitude": -122.4176811}, "state_code": "CA"}}]} 





并希望将此sting转换为datatable或Array

并非所有字段都是一些像名字,评论,..等等



寻找你的帮助



谢谢



and want to convert this sting to datatable Or Array
not all field but some of like name,reviews,..etc

looking for your help

thanks

推荐答案

请参阅 - 如何将json转换为数据表? [ ^ ]。

Refer - How to convert json into datatable?[^].
Quote:

假设您的JSON字符串是一个对象列表,每个对象将对应于DataTable中的一行,即:

Assuming that your JSON string is a list of objects, each object will correspond to a row in the DataTable, viz:

public DataTable DerializeDataTable()
{
    const string json = @"[{""Name"":""AAA"",""Age"":""22"",""Job"":""PPP""},"
                       + @"{""Name"":""BBB"",""Age"":""25"",""Job"":""QQQ""},"
                       + @"{""Name"":""CCC"",""Age"":""38"",""Job"":""RRR""}]";
    var table = JsonConvert.DeserializeObject<datatable>(json);
    return table;
}



这需要 Json.NET框架 [< a href =http://json.codeplex.com/target =_ blanktitle =New Window> ^ ]。


这篇关于将JSON字符串转换为datatable或Array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆