How do I parse JSON that is a single string with multiple files?

I’m having trouble getting the info from this JSON data. The data is a single string that contains multiple obj and corresponding mtl files. How can I parse or get the files to use in Unity?


This is a link to the JSON data:

https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=3djson&farm-widget-widget01_0000&layer=root_stat$lt=so$zo=2&layer=root-body1_FP00$lt=ro$zo=3$mat=maharam:466194-005&layer=root-arms-n_stat$lt=so$zo=9&layer=root-arms-n-arms1_FP00$lt=ro$zo=10$mat=maharam:466173-011


Here is the JSON itself:


[[[“widget01_root_stat.obj”,“https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=obj\u0026farm-widget-widget01\u0026obj=root_stat"],[“widget01_root_stat.mtl”,“https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=objmtl\u0026farm-widget-widget01\u0026obj=root_stat\u0026type=static”]],[[“widget01_root_body1.obj”,“https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=obj\u0026farm-widget-widget01\u0026obj=root_body1”],[“widget01_root_body1.mtl”,“https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=objmtl\u0026farm-widget-widget01\u0026obj=root_body1\u0026type=material\u0026dmat=maharam:466194-005”]],[[“widget01_root-arms-n_arms1.obj”,“https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=obj\u0026farm-widget-widget01\u0026obj=root-arms-n_arms1”],[“widget01_root-arms-n_arms1.mtl”,"https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=objmtl\u0026farm-widget-widget01\u0026obj=root-arms-n_arms1\u0026type=material\u0026dmat=maharam:466173-011”]]]


Any guidance is appreciated.
Thanks.

Well, the JSON data consists just of nested arrays. This is a problem for Unity’s JsonUtility as it always expects an object as top level element. Also the JsonUtility doesn’t support nested arrays. It has the same limitations as Unity’s serialization system. You may want to use my SimpleJSON parser. With that file in your project you can just do something like this:

var data = JSON.Parse(yourJsonText);
// this will iterate through all models
foreach(JSONNode obj in data)
{
    // this will iterate through all files in the current model
    foreach(JSONNode file in obj)
    {
        string fileName = file[0].Value;
        string fileURL = file[1].Value;
        // do something with the data
        Debug.Log("Name: " + fileName + " URL: " + fileURL);
    }
}

With your example JSON text this would print 6 debug log statements like those:

Name: widget01_root_stat.obj URL: https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=obj\u0026farm-widget-widget01\u0026obj=root_stat

Name: widget01_root_stat.mtl URL: https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=objmtl\u0026farm-widget-widget01\u0026obj=root_stat\u0026type=static

Name: widget01_root_body1.obj URL: https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=obj\u0026farm-widget-widget01\u0026obj=root_body1

Name: widget01_root_body1.mtl URL: https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=objmtl\u0026farm-widget-widget01\u0026obj=root_body1\u0026type=material\u0026dmat=maharam:466194-005

Name: widget01_root-arms-n_arms1.obj URL: https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=obj\u0026farm-widget-widget01\u0026obj=root-arms-n_arms1

Name: widget01_root-arms-n_arms1.mtl URL: https://machinecore.farmcp.com/Ziing3Server/Ziing3.aspx?req=objmtl\u0026farm-widget-widget01\u0026obj=root-arms-n_arms1\u0026type=material\u0026dmat=maharam:466173-011

You probably want to use the fileURL to download those files and use the fileName to identify the downloaded file.

// Use the System.Net Library
Using System.Net;

// Call this code to get the Json
var json = new WebClient().DownloadString("url");