2016-03-21 217 views
-1

我在jSon下面發佈我的WCF服務,讀取並保存數據庫中的值。將jSon轉換爲字典

{ 
    "business_name": "", 
    "fk_loan_id": "", 
    "proprietor_details": { 
     "office_address": { 
      "email_id": "", 
      "alternative_mobile_number": "", 
      "pincode": "", 
      "landline_number": "", 
      "city": "", 
      "flat_number": "", 
      "street": "", 
      "locality": "", 
      "state": "", 
      "mobile_number": "" 
     }, 
     "date_of_incorporation": "", 
     "financial_details": { 
      "TAN": "", 
      "TIN": "", 
      "VAT": "", 
      "PAN": "" 
     }, 
     "residence_address": { 
      "email_id": "", 
      "alternative_mobile_number": "", 
      "pincode": "", 
      "landline_number": "", 
      "city": "", 
      "flat_number": "", 
      "street": "", 
      "locality": "", 
      "state": "", 
      "mobile_number": "" 
     }, 
     "personal_details": { 
      "gender": "", 
      "date_of_birth": "", 
      "last_name": "", 
      "middle_name": "", 
      "first_name": "" 
     } 
    } 
} 

但我將「office_address」的值設爲null。請幫助。

+1

你試圖獲得'office_address'的代碼是什麼? – itzmukeshy7

回答

0
var address = JObject.Parse(json)["proprietor_details"]["office_address"]; 
+0

您能詳細解釋一下您提供的解決方案嗎? –

+0

一個基於令牌的Json解析 –

+0

嗨Amit,但我越來越對象作爲office_address的值。我可以做JObject.Parse(json)[「proprietor_details」] [「office_address」] ;?我使用下面的代碼將jSon轉換爲字典:[Serializable] public class JsonDictionary:protected JsonDictionary(SerializationInfo info,StreamingContext context) m_entries = new Dictionary (); foreach(info in info) m_entries.Add(entry.Name,entry.Value); } } –