Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET JSON array
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"}}]} 
 
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
Posted 9-May-13 22:27pm
Edited 13-May-13 22:52pm
v7
Comments
tumbledDown2earth at 10-May-13 3:43am
   
If you are using Json.Net you can deserialize the string to JObject and then have to manually build a datatable

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Refer - How to convert json into datatable?[^].
Quote:
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;
}
This requires the Json.NET framework[^].
  Permalink  
v2
Comments
Jimmy Darji at 10-May-13 3:54am
   
Thanks For Answer
the example that u given in your answer is working perfectly all right
but while i used my string it not working
Tadit Dash at 10-May-13 4:29am
   
The format might be the problem.
Can't you get the data in this format ?
Jimmy Darji at 10-May-13 5:07am
   
Thanks for your information
thank u very much
Tadit Dash at 10-May-13 5:51am
   
Hi Jimmy Darji,
 
Please accept this answer and up-vote, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...
 
Thanks,
Tadit
Tadit Dash at 14-May-13 2:38am
   
You rejected the solution... Is there any problem ? Or it is done by mistake ?
Nirav Prabtani at 29-Nov-13 0:59am
   
Hi tadit!!!, what kind of namespace i have to use for "JsonConvert"
Tadit Dash at 29-Nov-13 1:37am
   
Hi Nirav, as I said in my answer, it requires Json.NET[^]. So, download and try to use that.
Nirav Prabtani at 29-Nov-13 6:14am
   
Got it!!! ...thnx tadit.. :)
Tadit Dash at 29-Nov-13 7:59am
   
Most welcome Nirav. :)
Tadit Dash at 29-Nov-13 7:59am
   
Most welcome Nirav. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 205
3 Aajmot Sk 202
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 1 Oct 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100