我如何能够转换此值:
string str = ""m1":"DAF","m2":"LF55.220 E16","m3":"Africa Commercial Vehicles","m4":"sdgdf","m5":"gdfg"";
要正常的字符串?我可以在正面和背面添加更多的引用但我得到相同的错误。
我收到如下错误:
; expected
} expected
看起来很简单,但我无法弄清楚如何将其转换为字符串。
编辑:
这是我从应用程序中获得的另一个示例。该值是一个对象。
Object {1: "DAF", 2: "FA LF55.220 E15", 3: "Barloworld Isuzu Trucks City Deep", 4: "dsfsdfsdfdsfsddsfdsfdsf", 5: "fsdfdsfdsdsfdsfdsfdsfds", 6: "dsfdsfdsfdsfdfdssddsf", 7: "dsfsddsfdfdssdfsdfdsf", 8: "sfsdfdsfdsdfdsfsdfsfd", 9: "sdfdsfsdsdsdfdsfdsfds", 10: "Hankook", 11: "11", 12: Object, 13: "Yes", 14: "Repair", 15: "Yes", 16: "Yes", 17: "Yes", 18: "Yes", 19: "Yes", 20: "Yes", 21: "Yes", 22: "Yes", 23: "Yes", 24: "Yes", 25: "Yes", 26: "Yes", 27: "Yes", 28: "Yes", 29: "Yes", 30: "Yes", 31: "Yes", 32: "Yes", 33: "Yes", 34: "Yes", 35: "Yes", 36: "Yes", 37: "Yes", 38: "Yes", 39: "Yes", 40: "Yes", 41: "Yes", 42: "Yes", 43: "Yes", 44: "Yes", 45: "df sfsdfsdfdfsdf d fsf sdf sdfsd fsdf sdf", 46: "1"}
这是控制台日志中的值。
编辑2:这是方法。它来自另一个程序员,因为它是用javascript编写的。
$scope.postData = {
m1 : M1.Name,
m2 : M2.Name,
m3 : M3.Name,
m4 : M4,
m5 : M5,
...
};
var post = new Post($scope.postData);
post.$save(function(postObject) {
alert(JSON.stringify(postObject));
});
.factory('Post', function($resource) {
console.log('factory');
return $resource('http://localhost:53101/Service.svc/BOB');//addchecklist
});
编辑3:这是c#方法和WCF OperationContract
public string BOB(Stream streamdata)
{
StreamReader reader = new StreamReader(streamdata);
string res = reader.ReadToEnd();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i = 0; i < 100; i++)
{
sb.AppendLine(res);
}
sb.Replace(":", "|").Replace(",", "|").Replace("{", "").Replace("}", "");
string[] arData = sb.ToString().Split('|');
string a = arData[0];
string b = arData[1];
string c = arData[2];
string d = arData[3];
string e = arData[4];
string f = arData[5];
string g = arData[6];
string h = arData[7];
reader.Close();
reader.Dispose();
return "Received: " + res;
}
[OperationContract]
[WebInvoke(UriTemplate = "/BOB", Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string BOB(Stream streamdata);
答案 0 :(得分:2)
您应该做的是使用"
转义\"
。
string str = "\"m1\":\"DAF\",\"m2\":\"LF55.220 E16\",\"m3\":\"Africa Commercial Vehicles\",\"m4\":\"sdgdf\",\"m5\":\"gdfg\"";