从JSON中删除字符串 [英] Remove String from JSON

查看:260
本文介绍了从JSON中删除字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个数据存储(JsonRest)为一个dijit.form.Select(Dojo Select-Box)输入。问题是,JSON解析器只接受以下格式的JSON:

  [
{id:1 ,name:One1},
{id:2,name:Two1}
];

我们要调用的Web应用程序的REST API提供以下JSON:

  {
data:[
{id:1,name:One1},
{id:2,name:Two1}
],
total:2,
start:0,
sort ,
order:asc,
size:2
};

这就是为什么Select Box不显示任何数据。因此,我们需要删除{data:部分和JSON消息的最后部分将其传递到Dojo选择框。



数据存储在JsonRest对象中。所以问题是我们如何删除JSON的第一部分和最后一部分,只是这样给出了这个选择框:

  [
{id:1,name:One1},
{id:2,name:Two1}
];

感谢您的回答和最好的问候

解决方案

从dojo选择的数据中创建一个新的Array变量似乎很简单...

 var restapidataObj = {
data:[
{id:1,name:One1},
{id:2名称:Two1}
],
总:2,
开始:0,
排序:名称,
:asc,
size:2
};

var dojoSelectArray = restapidataObj.data;现在通过 dojoSelectArray 到dojo


I want to feed a dijit.form.Select (Dojo Select-Box) with a Data-Store (JsonRest). The Problem is, that the JSON-Parser only accepts JSON in this format:

[
  {id:"1", name:"One1"},
  {id:"2", name:"Two1"}
];

The REST-API of the webapplication we want to call delivers the following JSON:

{
  "data": [
      {id:"1", name:"One1"},
      {id:"2", name:"Two1"}
],
    "total": 2,
    "start": 0,
    "sort": "name",
    "order": "asc",
     "size": 2
};

That is why the Select Box does not show any data. Therefore, we need to remove the {"data": part and the last part of the JSON message bevore passing it to the Dojo Select Box.

The Data is stored in a JsonRest Object. So the question is how we can remove the first and the last part of the JSON in a way that simply this here is given to the Select-Box:

[
  {id:"1", name:"One1"},
  {id:"2", name:"Two1"}
];

Thank you for your answers and best regards Ben

解决方案

Create a new Array variable from the data for the dojo select seems simplest ...

var restapidataObj = {
  "data": [
      {id:"1", name:"One1"},
      {id:"2", name:"Two1"}
    ],
    "total": 2,
    "start": 0,
    "sort": "name",
    "order": "asc",
     "size": 2
};

var dojoSelectArray = restapidataObj.data;

Now pass dojoSelectArray to dojo

这篇关于从JSON中删除字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆