JSTree – why is it no longer studying from my JSON Array accurately however renders correctly when returned a unmarried JSON string?
I have been operating in this for days and cannot see to crack it! Cut-off dates are very shut and I’m filled with covid. Please please assist me crack it asap. I think like i have attempted each and every choice of sq. brackets, curly brackets however I simply can’t get JSTree to interpret it accurately from my Array. Once I go back a 1 line string the usage of the very same structure, JSTree accurately renders it as a folder with the right kind identify but if I go back the Array, JSTree displays an inventory of folders however they have got the entire string because the identify:
​
[https://i.imgur.com/A0U9gGi.png](https://i.imgur.com/A0U9gGi.png)
​
I have checked the JSON Array the usage of this checker: [https://jsonformatter.curiousconcept.com/](https://jsonformatter.curiousconcept.com/)
​
and it assessments correctly:
​
Returned Array:
​
[{“id”:”New Lib”,”parent”:”#”,”text”:”New Lib”,”data”:”0″},{“id”:”40″,”parent”:”New Lib”,”text”:”Text TXT”,”data”:”1″},{“id”:”39″,”parent”:”New Lib”,”text”:”new 5″,”data”:”2″},{“id”:”34″,”parent”:”New Lib”,”text”:”Hi”,”data”:”3″},{“id”:”41″,”parent”:”34″,”text”:”Test URL Facebook”,”data”:”4″},{“id”:”37″,”parent”:”34″,”text”:”Hi 2″,”data”:”5″}]
​
Output from the checker:
​
[
{
“id”:”New Lib”,
“parent”:”#”,
“text”:”New Lib”,
“data”:”0″
},
{
“id”:”40″,
“parent”:”New Lib”,
“text”:”Text TXT”,
“data”:”1″
},
{
“id”:”39″,
“parent”:”New Lib”,
“text”:”new 5″,
“data”:”2″
},
{
“id”:”34″,
“parent”:”New Lib”,
“text”:”Hi”,
“data”:”3″
},
{
“id”:”41″,
“parent”:”34″,
“text”:”Test URL Facebook”,
“data”:”4″
},
{
“id”:”37″,
“parent”:”34″,
“text”:”Hi 2″,
“data”:”5″
}
]
​
Possibly I want to parse it by hook or by crook? I have discovered this thread: [https://stackoverflow.com/questions/29498426/loading-json-as-variable-into-jstree](https://stackoverflow.com/questions/29498426/loading-json-as-variable-into-jstree)
​
However I do not know how to put into effect this into mine absolutely
​
C# Code:
​
[WebMethod]
public static Array getChildren(string libraryID)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[“ConnectionString”].ConnectionString);
[con.Open](https://con.Open)();
​
//Get the library identify
string getUserInfo = “choose LibraryName from Document_Library_Names the place Identification =” + libraryID;
SqlCommand getUserInfocmd = new SqlCommand(getUserInfo, con);
string libraryName = Convert.ToString(getUserInfocmd.ExecuteScalar()).Trim();
​
//Getting paperwork
string strGetDocuments = “Make a selection * from Paperwork the place LID =” + libraryID + ” order via DisplayOrder ASC”;
SqlCommand getDocumentsCMD = new SqlCommand(strGetDocuments, con);
getDocumentsCMD.ExecuteNonQuery();
​
DataTable dt = new DataTable();
SqlDataReader sqlDR = getDocumentsCMD.ExecuteReader();
dt.Load(sqlDR);
sqlDR.Shut();
​
if (dt != null)
{
if (dt.Rows.Rely > 0)
{
int arrayCount = dt.Rows.Rely;
int rowCount = 1;
string arrayEnd = “”;
​
string[] documentArray = new string[arrayCount+1];
​
//Listing<string> documentList = new Listing<string>();
documentArray[0] = “[{“id”:”” + libraryName + “”,”parent”:”#”,”text”:”” + libraryName + “”,”data”:”0″}]”;
​
//Construct the string
foreach (DataRow row in dt.Rows)
{
//Getting the knowledge
string ID = row[0].ToString().Trim();
string sort = row[2].ToString().Trim();
string identify = row[3].ToString().Trim();
string parentFolder = row[4].ToString().Trim();
string displayOrder = row[5].ToString().Trim();
string extension = row[8].ToString().Trim();
​
//Get parentFolder ID
string parentFolderID = “0”;
if (parentFolder != “”)
{
string strParentFolderID = “Make a selection ID from Paperwork the place Title=@Title and Kind=0”;
SqlCommand strParentFolderIDcmd = new SqlCommand(strParentFolderID, con);
strParentFolderIDcmd.Parameters.AddWithValue(“@Title”, parentFolder);
parentFolderID = Convert.ToString(strParentFolderIDcmd.ExecuteScalar());
}
else
{
parentFolderID = libraryName;
}
​
documentArray[rowCount] = “[{“id”:”” + ID + “”,”parent”:”” + parentFolderID + “”,”text”:”” + name + “”,”data”:”” + displayOrder + “”}]”;
rowCount = rowCount + 1;
}
con.Shut();
go back documentArray;
}
else
{
con.Shut();
go back null;
}
}
else
{
con.Shut();
go back null;
}
}
​
`<script sort=”textual content/javascript”>`
`const queryString = window.location.seek;`
`const urlParams = new URLSearchParams(queryString);`
`const libraryID = urlParams.get(‘ID’);`
`$(‘#libraryTreeview’).jstree({`
`”core”: {`
`”information”: {`
`sort: “POST”,`
`url: “LibraryFiles.aspx/getChildren”,`
`information: ‘{“libraryID”:”‘ + libraryID + ‘”}’,`
`contentType: “software/json; charset=utf-8”,`
`dataType: “json”,`
`luck: serve as (information) {`
`alert(information.d);`
`information.d;`
`$(information).every(serve as () {`
`go back { “identity”:` [`this.id`](https://this.id) `};`
`});`
`}`
`},`
`”issues”: {`
`dots: false,`
`//”variant”: “huge”,`
`//”responsive”: true`
`},`
`”varieties”: {`
`”FDR”: {`
`”icon”: “WebsiteImages/LibraryIcons/Folder48.png”`
`},`
`”IMG”: {`
`”icon”: “WebsiteImages/LibraryIcons/Image48.png”`
`}`
`},`
`”plugins”: [“types”, “themes”]`
`}`
`});`
`</script>`
​
That is my submit on SO: [https://stackoverflow.com/questions/74770727/jstree-why-is-it-not-reading-from-my-json-array-correctly-but-renders-properly](https://stackoverflow.com/questions/74770727/jstree-why-is-it-not-reading-from-my-json-array-correctly-but-renders-properly)
​
View Reddit via timedwards150 – View Supply