我想在下面的字符串中序列化模型: -
"{"name":"firstName","value":"john"}",
之后我想反序列化该字符串。它应该可以像这样访问:
returnString[0]["name"] //here name is the name of the property and returnString is the serialized string.
returnString[0]["value"] //here value is the value of the field
仅供参考,如果我们使用javascript执行类似的操作,我们可以获得JSON字符串: -
JSON.stringify(form.serializeArray())
但我的需要是生成服务器端。任何人都可以建议我最好的方法吗?
答案 0 :(得分:0)
您可以使用
序列化对象 Model = {name:'firstname',vlaue:'john'}
JSON.stringify(Model)
然后当你有一个像这样的序列化字符串变量
SerializedString='[{"name":"firstName","value":"john"},"name":"LastName","value":"Alexander"}]
'
您可以使用以下内容获取值:
ObjectsList =JSON.parse(SerializedString)
然后像这样使用它
ObjectsList[0]["name"]
ObjectsList[0]["value"]
我希望它会有所帮助
答案 1 :(得分:-1)
尝试在服务器端使用Json.Net为您序列化对象。