简体   繁体   中英

Parse JSON string using C#

I am trying to parse JSON string in C# solution, but I can't get the internal/nested arrays which start with : ",[["bd felek",0],["bdm",0],["bd",0],["bdz",

["bd",[["bd felek",0],["bdm",0],["bd",0],["bdz",0,[131]],["bd fleke",0],["bd felek dfdf",0],["bdz dance practice",0,[3]],["bdz twice live",0,[131]],["bdo",0,[131]],["bd mawlaya",0]],{"a":"Uwt304b6at0ZtuU8mv8D5AyWS8wg6AQJQbYlPPS8knOVvcG","e":"1","j":"6l","k":1,"q":"ZQXxB0vG-GaPEF2RNib3gbVRXt0"}]
    var jsonser = new JavaScriptSerializer();

            var obj = jsonser.Deserialize<dynamic>(SourceCodeTxt.Text);

            foreach (var x in obj)

            {

                // MessageBox.Show(x);
                String strvalue = x["value"];

            }
        }

Your code should be looking at the second index (1) of the deserialized object:

foreach (var x in obj[1])
{
    var value1 = x[0]; // bd felek
    var value2 = x[1]; // 0                               
}

You want to use JSON.NET to better handle JSON. then you can simply do the following:

using Newtonsoft.Json.Linq;

... 

JToken obj = JToken.Parse(/* Your JSON string goes in here */);
foreach (var x in obj[1])
{
    var value1 = x[0]; // bd felek
    var value2 = x[1]; // 0                               
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM