2015-10-24 119 views
0

我想发送一个复杂的json对象给我的动作,但没有运气。无效的JSON原语 - Asp.Net MVC 4

这里是我的javascript:

$.ajax({ 
    url: "http://localhost:52593/" + urlAction.Controller + "/" + urlAction.Action, 
    type: type, 
    dataType: dataType, 
    data: data, 
    contentType: contentType, 
    async: IsAsync, 
    traditional: traditional 
}).done(callback); 

这里的数据对象结构:

'"Pedido"={"Id":"null","produtos":[{"Id":6,"Quantidade":1,"Adicionais":[]}]}' 

当我提交了ajax,我得到这个异常:

Invalid JSON primitive: : {"Id":"null","produtos":[{"Id":6,"Quantidade":1,"Adicionais":[]}]} 

我在SO做了一些研究,并没有找到解决问题的方法。

有人可以帮助我吗?

谢谢。

+1

这不是一个有效的JSON对象。 “根”也必须是包裹在“{}”中的对象。 –

+0

你的asp.net c#代码是什么样的?你没有表现出来。 – dbc

回答

1

发送{"Id":"null","produtos":[{"Id":6,"Quantidade":1,"Adicionais":[]}]}'作为data而不是'"Pedido"={"Id":"null","produtos":[{"Id":6,"Quantidade":1,"Adicionais":[]}]}'。后者是无效的JSON。

+0

感谢您的回复。我只是尝试这个,但没有工作。 在此处查看http://prntscr.com/8un5y9 –

+0

您正在发送什么'contentType'? – Griffith

+0

我确实尝试过'text'和json –