Json incorporates the split problem

when the data is returned by the background, the two json are merged.
format such as:

 var str = "{"employees":[{"firstName":"Bill","lastName":"Gates"},{"firstName":"George","lastName":"Bush"},{"firstName":"Thomas","lastName":"Carter"}]}{"employees":[{"firstName":"Thomas","lastName":"Carter"}]}"
 
 

how do I split it?

Mar.10,2021

case by case
if the data returned by the backend is determined to be two and both json are returned with only one employees attribute:
use the lastIndexOf of string to find the split point

const i = str.lastIndexOf('{"employees":')
const result = [JSON.parse(str.substr(0, i)), JSON.parse(str.substr(i))]
console.log(result)

make sure they are all object and seamless

const arr = str.split('}{');
arr.length > 1 && arr.forEach((item, i) => {
  if (i === 0) {
    item += '}';
    console.log(JSON.parse(item));
  } else if (i === arr.length - 1) {
    item = '{' + item;
    console.log(JSON.parse(item));
  } else {
    item = `{${item}}`;
    console.log(JSON.parse(item));
  }
});
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b361ab-2bfdd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b361ab-2bfdd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?