===== UPDATED 8/20/2016 =====
latest version of fastjson can now handle
Dictionary<string, ?>
type correctly, my problem is solved now.=============================
I'm using fastjson to serialize the query result from Dapper, the table in DB has data like this:
id | name | price
1 | x | 100
2 | y | 200
....
And when I
using Dapper;
using fastJSON;
// ....
JSON.Parameters.KVStyleStringDictionary = false;
// ....
result = JSON.toJSON(conn.Query("SELECT * FROM tableX"));
I want the result to be:
[{"id":1,"name":"x","price":100},{"id":2,"name":"y","price":200},...]
However the actual result outputs:
[[{"Key":"id","Value":1},{"Key":"name","Value":"x"},{"Key":"price","Value":100}],
[{"Key":"id","Value":2},{"Key":"name","Value":"y"},{"Key":"price","Value":200}]...]
Lots of key-value pairs are generated which looks redundant.
Is there a way to get the correct result ?
Or should I switch to another JSON serializer ?
========== UPDATED ==========
makubex88's answer indicates that I can create a customized class mapping the table and use conn.Query<myClass>
to get the correct json, though it works for this scenario, it looks like I have to create hundreds of classes for every table in DB to get ideal json result, which is indeed tiring work for me. (Thanks any way:P)
Any alternative solutions would be highly appreciated!