Search Unity

Question Does Unity Support JSON?

Discussion in 'Scripting' started by mranatoliismirnov, Feb 24, 2021.

  1. mranatoliismirnov

    mranatoliismirnov

    Joined:
    Feb 24, 2021
    Posts:
    1
    Hi All,sorry im new one in this and it might be silly quest. im trying to add JSON Banner into my game but can't figure it out how it should works and how unity works with JSON.


    I got this script from my ads manager.

    curl -X POST "https://api.traffic.com/v1/banner/create" \
    -H "Authorization: Bearer oauth2_token" \
    -F "content=content" \
    -F "weight=1" \
    -F "campaign_id=10007" \
    -F "frequency_capping=1" \
    -F "urls=http://example.com/path1" \
    -F "urls=http://example.com/path2"
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Nothing above looks like JSON.

    Problems with Unity "tiny lite" built-in JSON:

    I highly suggest staying away from Unity's JSON "tiny lite" package. It's really not very capable at all and will silently fail on very common data structures, such as Dictionaries and Hashes.

    Instead grab Newtonsoft JSON .NET off the asset store for free, as it is way better.

    https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347

    PS: for folks howling about how it will "add too much size" to your game, JSON .NET is like 307k in size, and it has the important advantage that it actually works the way you expect a JSON serializer to work in the year 2021.
     
    Bunny83 and lordofduct like this.
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    Woah woah woah... my C64 only has 64K of RAM, do you expect my users to buy an expansion cart or something? Jeeeeez.
     
    Bunny83 and Kurt-Dekker like this.
  4. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    Alternatively you could also use the newtonsoft json package that Unity themselves use in entities.
    Click on the '+' and then add package from git url. Fill in com.unity.nuget.newtonsoft-json

    Usually the asset store versions of newtonsoft json are out of date.
    The newtonsoft-json package is currently synced up to 12.0.2