Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

334
Visualizações
Using LitJson in unity3d

2 questions.

1) Is it possible to use the LitJson library as is while scripting in Javascript? This is really a general question about being able to use c# source in javascript source.

2) I'm new to c# dev. I can't seem to get LitJson up and running. The following code throws this error: An object reference is required to access non-static memberLitJson.JsonReader.Read()'`

using UnityEngine;
using System.Collections;

public class Loadr : MonoBehaviour {
string url= "http://developer.echonest.com/api/v4/artist/images?api_key=N6E4NIOVYMTHNDM8J&id=ARH6W4X1187B99274F&format=json&results=1&start=0&license=unknown";
void  Start (){
    WWW www = new WWW(url);
    print(www.text);
    Object a = LitJson.JsonReader.Read(www.text);
    print(a.response.status);

    }

}

any thoughts?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

I've been through a bunch of Json libraries in Unity3D. The only one I've found that doesn't have weird serialization/deserialization quirks, and works consistently in iOS, WebPlayer, and Editor is JsonFX JsonSerializer 1.4.

That said, I think your problem is that you have to instantiate a JsonReader before you can use it's methods.

Something like this might work:

var reader = new LitJson.JsonReader();
Object a = reader.Read(www.text);

Edit:

Whoops, I skipped part of your question. You should be able to using any managed assembly from UnityScript, just like from C#. Instead of including namespaces with using, you use import. After that the code would be virtually identical to the C# version, except for the way UnityScript defines types (var blah : Type = YadaYada();)

over 4 years ago · Santiago Trujillo Relatório

0

Hm. Have you tried Jayrock? Its code looks OK, but there isn't any documentation to speak of, and the author is satisfied to leave it that way.

over 4 years ago · Santiago Trujillo Relatório

0

Have a look at the LitJSON fork for Unity3D:


Actually LitJson has some issues and is not always working as expected, so I created a simple JSON-Lib that can handle all Unity3D Types, Enums and arbitrary classes.

Find it at GitHub: Tiny-JSON

You can use it very simple:

// encode
Animal a = new Animal(4);
string json = Json.Encode(a);

// decode
IList<Animal> a = Json.Decode<IList<Animal>>("[{\"legs\":4}, {\"legs\":2}]");
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda