mirror of
https://gitee.com/eolink_admin/postcat.git
synced 2024-12-02 11:47:57 +08:00
fix: xml2json bug
This commit is contained in:
parent
207fd9bc43
commit
3a92c59242
@ -96,7 +96,7 @@ export const xml2json = (tmpl) => {
|
|||||||
let index = null;
|
let index = null;
|
||||||
while (xml) {
|
while (xml) {
|
||||||
// * handle end tags
|
// * handle end tags
|
||||||
if (xml.trim().substring(0, 2) === '</') {
|
if (xml.substring(0, 2) === '</') {
|
||||||
const end = xml.match(endTag);
|
const end = xml.match(endTag);
|
||||||
const [str, label] = end;
|
const [str, label] = end;
|
||||||
const last = stack.pop();
|
const last = stack.pop();
|
||||||
@ -110,7 +110,7 @@ export const xml2json = (tmpl) => {
|
|||||||
parent.children.push(last);
|
parent.children.push(last);
|
||||||
stack.push(parent);
|
stack.push(parent);
|
||||||
}
|
}
|
||||||
xml = xml.trim().substring(str.length);
|
xml = xml.trim().substring(str.length).trim();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// * handle start tags
|
// * handle start tags
|
||||||
@ -185,7 +185,7 @@ export const xml2UiData = (text) => {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const json2XML: (o: object, tab?) => string = (o, tab) => {
|
export const json2XML: (o: object, tab?) => string = (o, tab) => {
|
||||||
const toXml = function(v, name, ind) {
|
const toXml = function (v, name, ind) {
|
||||||
let xml = '';
|
let xml = '';
|
||||||
if (v instanceof Array) {
|
if (v instanceof Array) {
|
||||||
for (let i = 0, n = v.length; i < n; i++) {
|
for (let i = 0, n = v.length; i < n; i++) {
|
||||||
@ -241,7 +241,7 @@ export const text2UiData: (text: string) => uiData = (text) => {
|
|||||||
data: text,
|
data: text,
|
||||||
};
|
};
|
||||||
const textType = whatTextType(text);
|
const textType = whatTextType(text);
|
||||||
result.textType = ['xml', 'json'].includes(textType) ? textType as ApiBodyType : ApiBodyType.Raw;
|
result.textType = ['xml', 'json'].includes(textType) ? (textType as ApiBodyType) : ApiBodyType.Raw;
|
||||||
switch (result.textType) {
|
switch (result.textType) {
|
||||||
case 'xml': {
|
case 'xml': {
|
||||||
result.data = xml2UiData(text);
|
result.data = xml2UiData(text);
|
||||||
@ -268,7 +268,7 @@ export const text2UiData: (text: string) => uiData = (text) => {
|
|||||||
* @param inputOptions
|
* @param inputOptions
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const uiData2Json = function(eoapiArr: ApiEditBody[], inputOptions) {
|
export const uiData2Json = function (eoapiArr: ApiEditBody[], inputOptions) {
|
||||||
inputOptions = inputOptions || {};
|
inputOptions = inputOptions || {};
|
||||||
let result = {};
|
let result = {};
|
||||||
const loopFun = (inputArr, inputObject) => {
|
const loopFun = (inputArr, inputObject) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user