2014-08-28 4 views
1
를 사용하여 C 번호와 함께이 JSON을 구문 분석하는 방법

확인이는 내가json.net

내가 원하는 것은 간단하지만 난 어떻게 성공적으로 가지고 그것을

을 달성하기 위해 아무 생각을 포맷 할 예제 JSON 문자열 JObject myJsonNetObject = JObject.Parse(jsonCode);

Q1 : 설치 json.net

나는 다음과 같은 JSON 문자열을로드 내가 json.net.linq으로 그렇게 어떻게 "결과"의 각 요소 사이를 이동하려면?

Q2 : 나는,

foreach (var vrElement in myJsonNetObject.select(???)) { string commentid= vrElement.CommentId; //or string commentid= vrElement["CommentId"]; ?? } 

당신에게 대답 .NET

C# WPF, 4.5 대단히 감사합니다 이름

뭔가

등을주는 특정 개체 매개 변수를 얻으려면 Json.NET 6.0.4

{ 
    "RenderedTime":"2014-08-28 03:00:27", 
    "succeded":true, 
    "result":[ 
     { 
     "CommentId":79107, 
     "ContentTypeId":8, 
     "ContentId":0, 
     "ProductId":"110015198", 
     "ProductName":"LG 32LB652V DVB-S2/T2/C 3D FHD WEBOS SMART LED LCD TV + 2 GÖZLÜK", 
     "FirstLastName":"ERGUN GOKCUOGLU", 
     "Gender":1, 
     "TimeUsed":"1-3 Ay", 
     "City":"İzmir", 
     "BirthRange":"36-50 arası", 
     "Comment":"Cihazı kullanmaya başladım ürün fena değil görüntü kalitesi iyi içerisinden çıkan 3d pasif gözlük 310 modeli yani çok iyi değil kumanda akıllı kumanda olmadığı için büyük ve işlevi çok iyi değil ama paranın karşılığı bir ürün alınabilir.", 
     "Eof":false, 
     "NameVisible":false, 
     "Onay":1, 
     "ContentType":"comment", 
     "GoodCount":0, 
     "BadCount":0, 
     "Id":{ 
      "Type":0, 
      "Id":null, 
      "IdGuid":null, 
      "HasValue":false 
     }, 
     "ExtendedProperties":[ 

     ] 
     }, 
     { 
     "CommentId":78954, 
     "ContentTypeId":8, 
     "ContentId":0, 
     "ProductId":"110015198", 
     "ProductName":"LG 32LB652V DVB-S2/T2/C 3D FHD WEBOS SMART LED LCD TV + 2 GÖZLÜK", 
     "FirstLastName":"volkan yıldırım", 
     "Gender":1, 
     "TimeUsed":"1-3 Ay", 
     "City":"Rize", 
     "BirthRange":"18-25 arası", 
     "Comment":"Dün aldım kurcaladım gayet iyi çok menmun kaldım interneti smart tvsi çözünürlük 10 numara bi kalite bu fiyat çok iyi 81 ekran için en ideal cihaz", 
     "Eof":false, 
     "NameVisible":false, 
     "Onay":1, 
     "ContentType":"comment", 
     "GoodCount":0, 
     "BadCount":0, 
     "Id":{ 
      "Type":0, 
      "Id":null, 
      "IdGuid":null, 
      "HasValue":false 
     }, 
     "ExtendedProperties":[ 

     ] 
     }, 
     { 
     "CommentId":78789, 
     "ContentTypeId":8, 
     "ContentId":0, 
     "ProductId":"110015198", 
     "ProductName":"LG 32LB652V DVB-S2/T2/C 3D FHD WEBOS SMART LED LCD TV + 2 GÖZLÜK", 
     "FirstLastName":"ATAKAN ÇELİK", 
     "Gender":1, 
     "TimeUsed":"Seçiniz", 
     "City":"Seçiniz", 
     "BirthRange":"Seçiniz", 
     "Comment":"ürün çok güzel ve sık bir tasarıma sahip güzel bir akıllı televizyon lg yapıyo arkadaşlar ve kendilerini devamlı geliştiriyorlar şimdi webos özelliğide koymuşlar çok çok güzel", 
     "Eof":false, 
     "NameVisible":false, 
     "Onay":1, 
     "ContentType":"comment", 
     "GoodCount":0, 
     "BadCount":0, 
     "Id":{ 
      "Type":0, 
      "Id":null, 
      "IdGuid":null, 
      "HasValue":false 
     }, 
     "ExtendedProperties":[ 

     ] 
     }, 
     { 
     "ContentType":"recommendation", 
     "Eof":false, 
     "Id":{ 
      "Type":0, 
      "Id":null, 
      "IdGuid":null, 
      "HasValue":false 
     }, 
     "ExtendedProperties":[ 

     ] 
     }, 
     { 
     "CommentId":76687, 
     "ContentTypeId":8, 
     "ContentId":0, 
     "ProductId":"110015198", 
     "ProductName":"LG 32LB652V DVB-S2/T2/C 3D FHD WEBOS SMART LED LCD TV + 2 GÖZLÜK", 
     "FirstLastName":"ATİLLA KASIMOĞLU", 
     "Gender":1, 
     "TimeUsed":"1-5 Ay", 
     "City":"Adıyaman", 
     "BirthRange":"36-50 arası", 
     "Comment":"ürünün kasasi o kadar iyi olmasada islemcinin biraz düsük olmasi bu led tv eksik yönleri ama 500 mhz olmasi webos olmasi da avantajlarindan alinacak tvlerden biri", 
     "Eof":true, 
     "NameVisible":true, 
     "Onay":1, 
     "ContentType":"comment", 
     "GoodCount":0, 
     "BadCount":0, 
     "Id":{ 
      "Type":0, 
      "Id":null, 
      "IdGuid":null, 
      "HasValue":false 
     }, 
     "ExtendedProperties":[ 

     ] 
     } 
    ], 
    "error":null 
} 
+0

의 중복 가능성 http://stackoverflow.com/questions/4535840/deserialize- json-object-using-json-net) –

+0

http://james.newtonking.com/json/help/index.html?topic=html/QueryJsonSelectTokenWithLinq.htm – Donal

답변

2

그다지 멀지 않습니다. 이런 식을 시도

JObject myJsonNetObject = JObject.Parse(jsonCode); 

foreach (JObject item in myJsonNetObject["result"]) 
{ 
    if (item["ContentType"].ToString() == "comment") 
    { 
     Console.WriteLine("CommentId: " + item["CommentId"]); 
     Console.WriteLine("City: " + item["City"]); 
     // etc.. 
    } 
} 

데모 : https://dotnetfiddle.net/1Zd73d

([Json.net를 사용하여 동적 객체로 탈 직렬화 JSON 오브젝트]
+0

대단히 감사합니다. 나는 주제를 알고 정확한 대답을주는 너와 같은 사람들을 정말 좋아한다 : D – MonsterMMORPG

+0

문제 없음; 기꺼이 도와주세요. –