C#函数返回JSON,意外错误



我有一个C#函数

 public JObject MessageJSON(string dv, string sip)
            {
                JArray details = new JArray();
                //Gr 1
                JArray detail = new JArray();
                JObject detailR = new JObject();
                detailR["dt"] = "int";
                detailR["dn"] = "status";
                detailR["dv"] = dv;
                detail.Add(detailR);
                //Gr 2
                JObject issuerobj = new JObject();
                issuerobj.Add("sid", "2");
                issuerobj.Add("sip", sip);
                issuerobj.Add("storeid", 9999);
                issuerobj.Add("timestamp", 1390236777);

                //list of events
                JObject objectJS = new JObject();
                objectJS.Add(detail);
                objectJS.Add(issuerobj);

                JArray ret = new JArray();
                ret.Add(objectJS);
                JObject stringJSON = new JObject();
                stringJSON.Add(ret);
                return stringJSON;
            }

我需要从功能返回这样的JSON:

{ "events" : [ { "event" : { "details" : [ { "dn" : "status",
                  "dt" : "int",
                  "dv" : 2
                } ],
            "issuer" : { "sid" : 2,
                "sip" : "192.168.1.125",
                "storeid" : 9999,
                "timestamp" : 1390236777
              },
            "type" : "VRA3.5_SCREEN"
          } } ] }

问题之一是,当我尝试将列表添加到对象时,我有错误。

高级感谢

更改

objectJS.Add(detail);
objectJS.Add(issuerobj);

to

objectJs["details"] = detail;
objectJs["issuer"] = issuerobj;

stringJSON.Add(ret) to stringJSON["events"] = ret

相关内容

  • 没有找到相关文章

最新更新