我有一个必须返回JSON的wcf服务。我的代码如下所示:WCF回归糟糕JSON
{ “areaGetStreetTypesResult”:
public String areaGetStreetTypes(int city_id, int language_id) { string json = ""; string responseList = "{\"triname\":\"IMP\",\"name\":\"IMPASSE\"}"; if (responseList.Length != 0){ string responseStatusJSON = "{\"status\":0, \"message\":\"Success !!!\"}"; json += "{\"responseList\":[" + responseList + "],"; json += "\"responseStatus\":" + responseStatusJSON + "}"; } else{ string responseStatusJSON = "{\"status\":1, \"message\":\"Error !!!\"}"; json += responseStatusJSON; } return json; } //my interface looks like [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "areaGetStreetTypes", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] String areaGetStreetTypes(int city_id, int language_id);
原始格式的响应 “{\” responseList \ “:[{\” triname \ “:\” IMP \”, \“name \”:\“IMPASSE \”}],\“responseStatus \”:{\“status \”:0,\“message \”:\“Success !!! \”}}“}
我使用php脚本进行测试。第一解码后:
stdClass的对象(
[areaGetStreetTypesResult] => {"responseList":[{"triname":"IMP","name":"IMPASSE"}],"responseStatus":{"status":0, "message":"Success !!!"}}
)
只有在我的第二个json_decode我得到我想要的东西:GOOD JSON Response
我可以在我的服务改变什么第一次获得好的JSON?我只想解码一次。
这只是一个测试。我不能实现一个固定类型,因为我从数据库动态获取数据。我不知道返回的列号或列的名称。 –