猿问

使用 C# 解析 JSON 字符串

我正在尝试在 C# 解决方案中解析 JSON 字符串,但我无法获取以以下内容开头的内部/嵌套数组: ",[["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"];


            }

        }


MMMHUHU
浏览 207回答 2
2回答

holdtom

您想使用 JSON.NET 更好地处理 JSON。那么您可以简单地执行以下操作:using Newtonsoft.Json.Linq;...&nbsp;JToken obj = JToken.Parse(/* Your JSON string goes in here */);foreach (var x in obj[1]){&nbsp; &nbsp; var value1 = x[0]; // bd felek&nbsp; &nbsp; var value2 = x[1]; // 0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; ...}

汪汪一只猫

您的代码应该查看反序列化对象的第二个索引 (1):foreach (var x in obj[1]){&nbsp; &nbsp; var value1 = x[0]; // bd felek&nbsp; &nbsp; var value2 = x[1]; // 0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
随时随地看视频慕课网APP
我要回答