简体   繁体   English

FastJSON - 如何使用?

[英]FastJSON - How to use?

I've started using FastJSON and I'm having some problems for use it. 我已经开始使用FastJSON,我遇到了一些使用它的问题。 I can't find any guide or documentation in internet, only a little extract in CodeProject. 我在互联网上找不到任何指南或文档,只有CodeProject中的一些摘录。

For example: I've got this class: 例如:我有这个课程:

[Serializable]
public class Prueba
{
    public Prueba()
    {
        prueba1 = 5;
        prueba2 = 6;
        prueba3 = "Hola";
    }

    public int prueba1 { get; set; }
    public int prueba2 { get; set; }
    public string prueba3 { get; set; }
}

If I execute fastJSON.JSON.ToJSON(new Prueba()) i am getting this string: 如果我执行fastJSON.JSON.ToJSON(new Prueba())我得到这个字符串:

{"$types":{"WebApplication3.Prueba, WebApplication3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null":"1"},"$type":"1","prueba1":5,"prueba2":6,"prueba3":"Hola"} {“$ types”:{“WebApplication3.Prueba,WebApplication3,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null”:“1”},“$ type”:“1”,“prueba1”:5,“ prueba2 “:6,” prueba3 “:” HOLA“}

But I was expecting this string: 但我期待这个字符串:

"{"prueba1":5,"prueba2":6,"prueba3":"Hola"}" “{” prueba1 “:5”,prueba2 “:6,” prueba3 “:” HOLA “}”

As you can see, it is including some assembly information that I don't want in the string. 如您所见,它包含了我不希望在字符串中的一些汇编信息。 I have tried playing with JSONParameters class, but I don't see any property for this situation. 我曾尝试使用JSONParameters类,但我没有看到任何属性。

So... Do you know how configure this?? 那么......你知道如何配置吗? Do you know any guide or documentation on internet to understand well how fastJSON works?? 你知道互联网上的任何指南或文档,以了解fastJSON的工作原理吗?

Thanks a lot, Regards 非常感谢,问候

Try setting UseSerializerExtension to false: 尝试将UseSerializerExtension设置为false:

Something like: 就像是:

fastJSON.JSON.Instance.UseSerializerExtension = false;
fastJSON.JSON.ToJSON(new Prueba());

EDIT 编辑

It appears the API has changed. 似乎API已经改变了。 You now need to pass an instance of JSONParameters 您现在需要传递JSONParameters的实例

Like this 像这样

fastJSON.JSON.ToJSON(new Prueba(), new JSONParameters(){UseExtensions = false});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM