0

I have a result that contains Json result. The Json Result are as follows.

      <string xmlns="http://tempuri.org/">
        {"Method":"LOGIN_AUTHENTICATE Start :8/29/2013 1:23:46 AM 
          ASW :8/29/2013 1:23:46 AM P21 :8/29/2013 1:23:50 AM End :8/29/2013 1:23:50AM",
        "ResponseCode":0,"ResponseText":"","HomeBannerURL":"http://example.com/example/",
        "resAccount":[{"shopper_uid":1877,"customer_code":"10950",
         "customer_name":"JASPER ACCOUNT",
         "contact_id":6449,"first_name":"jasper","last_name":"manickaraj",
         "email_address":"[email protected]","password_hint":"name",
         "default_shipping_method_uid":110,"password":"abc123",
         "default_ship_to_address_id":"150"}],
         "resCategories":
 [{"item_category_uid":123,
        "item_category_desc":"EFG",
        "Total":0,"sub_category_image":"",
        "sub_category_thumb":""},
 {"item_category_uid":1,
        "item_category_desc":"ABC",
        "Total":0,"sub_category_image":"",
        "sub_category_thumb":""},
 {"item_category_uid":2,
        "item_category_desc":"BCD",
        "Total":0,"sub_category_image":"",
        "sub_category_thumb":""},
 {"item_category_uid":3,
        "item_category_desc":"CDE",
        "Total":0,"sub_category_image":"",
        "sub_category_thumb":""}]}
    <string>

Now i assign the above result to var Jsonresult; Now i need to get the customer_name, first_name from Jsonresult.. How to get the result.. Please help me to fix this..

1
  • Jsonresult.customer_name does not work? Commented Aug 29, 2013 at 7:49

2 Answers 2

2

Use JavaScriptSerializer to implement this feature. First,you must define a few entity,eg.

public class RequestObj
{
    public string Method { get; set; }
    public string ResponseCode { get; set; }
    public string HomeBannerURL { get; set; }

    public IList<Account> ResAccount { get; set; }
}

public class Account
{

    public string shopper_uid { get; set; }

    public string customer_name { get; set; }

    public string first_name { get; set; }
}

second,you can deserialize your string.

var scriptSerializer = new JavaScriptSerializer();
var obj = scriptSerializer.Deserialize<RequestObj>(str);
Sign up to request clarification or add additional context in comments.

Comments

1

Ok,you must add json.net dll in your project,and you such so write code:

var obj = JsonConvert.DeserializeObject<Dictionary<string, object>>(str.ToString());

1 Comment

json.net dll is not available

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.