从JSON数据获取值

我有这个Json数据需要在vb.net上获取值

{
    "type": "push","targets": ["stream"],"push": {
        "type": "mirror","source_device_iden": "ujzp6Xr9A4asjyjskXPzu8","source_user_iden": "ujzp6Xr9A4a","client_version": 354,"dismissible": true,"icon": "ok","title": "test","body": "Hi","application_name": "WhatsApp","package_name": "com.whatsapp","notification_id": "1","notification_tag": "y9x5Q2YAI\/pqPhZwbaN6TpoW4eJhe0kAe0HfmWOQyWA=\n","conversation_iden": "{\"package_name\":\"com.whatsapp\",\"tag\":\"y9x5Q2YAI\\\/pqPhZwbaN6TpoW4eJhe0kAe0HfmWOQyWA=\\n\",\"id\":1}"
    }
}

我尝试了这段代码,这是返回错误

 Dim json As String = TextBox1.Text
      Dim ser As JObject = JObject.Parse(json)
        Dim data As List(Of JToken) = ser.Children().ToList

        For Each item As JProperty In data
            item.CreateReader()
            Select Case item.Name

                Case "push"
                    For Each msg As JObject In item.Value

                        Dim tyep As String = msg("type")
                        Dim source As String = msg("source_device_iden")

                    Next
            End Select


        Next
  

System.InvalidCastException:'无法转换类型的对象   键入“ Newtonsoft.Json.Linq.JProperty”   “ Newtonsoft.Json.Linq.JObject”。

jp1004 回答:从JSON数据获取值

private final String DIALOG_MESSAGE = "Sending message";

private ProgressDialog mDialog = null;

private void setDialog(Context context) {
    this.mDialog = new ProgressDialog(context);
    this.mDialog.setMessage(DIALOG_MESSAGE);
    this.mDialog.setCancelable(false);
}

public MyAsyncTask(Context context) {
    this.setDialog(context);
}

@Override
protected void onPreExecute() {
    this.mDialog.show();
}

@Override
protected Result doInBackground(Params... arg0) {

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    return null;
}

@Override
protected void onPostExecute(Result result) {

    if (this.mDialog.isShowing()) {
        this.mDialog.dismiss();
    }
} }
本文链接:https://www.f2er.com/3154120.html

大家都在问