I have a json file in my android local device, im able to read and edit the json file and store json data in it.
But the problem is arising when i want to insert new element in the json file. Im able to change the value of existing variables.
the json file data is:
var data = {items:
{id: "1", name: "Snatch", type: "crime"}
};
i want to add one more element to it so that json file will look like
var data = {items: [
{id: "1", name: "Snatch", type: "crime"},
{id: "7", name: "Douglas Adams", type: "comedy"}
};
i tried with
data.items.push{id: "7", name: "Douglas Adams", type: "comedy"}
but its not working.
im creating android app using phonegap framework with telerik IDE.
Try
data.items.push(
{id: "7", name: "Douglas Adams", type: "comedy"}
);
You are missing ()
Your first file example is missing []
Check out this links to know more about json addition and removal
Link 1 , Link 2
Related
I'm writing an external app that loads it's data from a drupal site, the site implemented "services" module which returns JSON representation of a node and (almost) all of it's data.
the one thing the service does not return is the url of the requested node,
so I'm calling this:
[domain]/rest/mynode/ffad3c26-e684-4cca-9c4b-16334f9f3dc1.json
and getting this:
{
vid: "2087",
uid: "67133de7-9755-424d-b45b-c4bbf41cb00e",
title: "PD300",
log: "Updated by FeedsNodeProcessor",
status: "1",
comment: "0",
promote: "0",
sticky: "0",
vuuid: "097f43ef-e22c-4f35-b74d-02b8e8ac5895",
nid: "2087",
type: "product",
language: "en"... and some more
I also need the url for the current node so I can link back to it from the app, any idea?
I think you just need to concatenate in your application the string something like that:
URL= "[domain]"."/node/"."{nid}"
Can any body explain me how to parse the below code in JSON. When I remove {type: 'string', role: 'tooltip'} and \"huu\", I am able to generate the chart
Code Snippet :
var obj=JSON.parse("[[\"Carrier Name\",{type: 'string', role: 'tooltip'}, \"Transactions\", \"Spending\", \"Chargeable Weight\"], [\" - AK - AirAsia Berhad dba AirAsia\",\"huu\", 15, 0.8778833367217757, 0.9236859587487404]]");
var data = google.visualization.arrayToDataTable(obj);
{type: 'string', role: 'tooltip'} is a syntax error from JSON perspective. You should change that part to {"type": "string", "role": "tooltip"}. I did not face any problems with "huu" when I validated the JSON string using JSOnLint. JSONLint may not work on recent FF. Use chrome.
I am trying to reload (via ajax) data into a Gantt chart using php and jquery. I can draw a gantt chart with my data on the initial load without any issues. I have a ajax save call to update chart data in which I would like to redraw the gantt chart after a successful save.
I am able to load part of the data, ie the title data on the left, but not the dates, I believe it is not in the right format? I am using this gantt chart plugin from github: https://github.com/thegrubbsian/jquery.ganttView
Below is a sample of the data they are using? Is this json data?
I am not sure? How do I format my output to mirror and use this data.
var ganttData = [
{
id: 1, name: "Feature 1", series: [
{ name: "Planned", start: new Date(2010,00,01), end: new Date(2010,00,03) },
{ name: "Actual", start: new Date(2010,00,02), end: new Date(2010,00,05), color: "#f0f0f0" }
]
},
{
id: 2, name: "Feature 2", series: [
{ name: "Planned", start: new Date(2010,00,05), end: new Date(2010,00,20) },
{ name: "Actual", start: new Date(2010,00,06), end: new Date(2010,00,17), color: "#f0f0f0" },
{ name: "Projected", start: new Date(2010,00,06), end: new Date(2010,00,17), color: "#e0e0e0" }
]
},
My code looks like this:
[{"id":0,"name":"task number 20","series":[{"name":"Bob","start":"new Date(2012,2,19)","end":"new Date(2012,6,11)"}]},{"id":1,"name":"another new posts","series":[{"name":"Bill","start":"new Date(2012,5,22)","end":"new Date(2012,6,27)"}]},here
It's not legal to "call" functions (including constructors) from a json string. JSON isn't anything you can pass to an eval function : http://www.json.org/
You should do the transformation from string to date in your javascript code.
You can send
[{..."start":"Thu Jul 12 2012 16:20:17 GMT+0200 (CEST)"...}]
and in your js code, just after json parsing, iterate over the objects to do
myobj.start = new Date(myobj.start);
I have an external source that generates JSON in given format. I need to use ScriptTagProxy to access that data. Format of data is (two records):
{
"COLUMNS":["KEDBID","EMPID","KE","SOLUTION","ATTACH_KE","ATTACH_SOLUTION"],
"DATA":[
[1,36661,"While adding a new user, if his\/her profile is missing, it could be LDAP server issue.","Contact Mr. ABC from infra team to get user's profile corrected on server","screenshots.jpg","conacts.doc"],
[2,36661,"The error code # 123445 is trivial that may occur at particular time.","To resolve this issue, we will need to ask DBA team to refresh database. That will fix this type of errors","NA","NA"]
]
}
How to define jsonreader for this data? As i have seen that root should be like:
{ROOT: [ {field1:data1,field2:data1},{field1:data2,field2:data2}]}
while my JSON is like:
{fieldnames:['field1','field2'],
ROOT:[ [data1ForField1,data1ForField2],[data2ForField1,data2ForField2] ]
}
UPDATE
Adding one more case:
Similarly can we have a jsonreader for;
{"ROWCOUNT":8,
"COLUMNS":["CATID","CATEGORY"],
"DATA":{"CATID":[1,2,3,4,5,6,7,8],"CATEGORY":["Optimization","Automation","Process Improvement","Tool","Other","Another One","ThisHas'","More^!##(){}"]}}
where 1-->Optimization, 2-->Automation, 3-->Process Improvement etc.
Basically I need to return data from ColdFusion query object by serializing query object. Serialization in CF Query can return data in above two formats.
I'm still new to Ext World!! Hope to get some support.
Best Regards,
Tushar Saxena
Below is the code where I'm facing issue. The data is being coming up in store as it is available to ComBox.. but not able to read data using each function or by other means? So is it that Data in store can only be fed to components? In another example I created a simplestore (ArrayStore) paased data manually using loadDATA().. there each function was working!!!
In below case to if I add one record after load using ADD(), each function would get executed one time showing data that I just added... and that just added data is not available to components!!! How come!!!
May be I'm missing some very basic concept as I'm still very new to EXT.
Would be really greatful for response.
var proxy = new Ext.data.ScriptTagProxy({
url: 'http://127.0.0.1:8500/extex/kebyid.cfm',
method: 'POST'
});
var rec = Ext.data.Record.create([
{name: 'EMPID', mapping: 1},
{name: 'KE', mapping: 2},
{name: 'SOLUTION', mapping: 3},
{name: 'ATTACH_KE', mapping: 4},
{name: 'ATTACH_SOLUTION', mapping: 5}
]);
var myReader = new Ext.data.ArrayReader({
idIndex: 0,
root: 'DATA'
}, rec);
var store = new Ext.data.ArrayStore({
proxy: new Ext.data.HttpProxy({
url: '/extex/kebyid.cfm',
method: 'POST'
}),
autoSave: true,
autoLoad: true,
root: 'DATA',
fields: [
{name: 'KEID', mapping: 0},
{name: 'EMPID', mapping: 1},
{name: 'KE', mapping: 2},
{name: 'SOLUTION', mapping: 3},
{name: 'ATTACH_KE', mapping: 4},
{name: 'ATTACH_SOLUTION', mapping: 5}
]
});
store.each(function(){
alert('!!!!'); //**************NOT WORKING
});
var catCB = new Ext.form.ComboBox({
fieldLabel: 'Category',
layout:'absolute',
x: 100,
y: 5,
store: store, //************* DATA IS THERE AS STORE IS PROVIDING DATA TO COMBOBOX
emptyText:'Select Category...',
valueField : 'KEID',
displayField : 'KE',
hiddenName : 'category',
hiddenvalue : 'None',
mode: 'local',
editable : false,
lastQuery: '',
renderTo: Ext.get("d1"),
listeners: {
'beforequery': function(qe){
qe.forceAll = true;
}}
});
First of all, you cannot use your server's output for scriptTagProxy. scriptTagProxy utilises JSONP technology. So output should look like this:
callback({
"COLUMNS":["KEDBID","EMPID","KE","SOLUTION","ATTACH_KE","ATTACH_SOLUTION"],
"DATA":[
[1,36661,"While adding a new user, if his\/her profile is missing, it could be LDAP server issue.","Contact Mr. ABC from infra team to get user's profile corrected on server","screenshots.jpg","conacts.doc"],
[2,36661,"The error code # 123445 is trivial that may occur at particular time.","To resolve this issue, we will need to ask DBA team to refresh database. That will fix this type of errors","NA","NA"]
]
});
Then simply use ArrayStore as your store. It uses ArrayReader by default:
var store = new Ext.data.ArrayStore({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://example.com/get_data.php'
}),
root: 'DATA',
fields: [
'id',
// ...,
// ...,
// ...
]
});
UPDATE
I forgot that you are using 'DATA' as root property. Added it to store config.
I am creating a tree in ExtJS 3.4.0. I understand the JSON the component is expecting should be returned like this:
[{
id: 1,
text: 'Brian',
leaf: true,
checked: false
}]
but the JSON that i am getting retrurned to me has a root node like this:
{"message":
{"nodes":
[{
"text":"Brian",
"id":"1",
"leaf":true,
"checked":false
}]
}
}
I don't see a way to specify in my configuration where in the JSON, the actual tree data is. Is this even possible? I see a "root" paramater, but that is different. Is there a way to specify where in the incoming JSON to "start" from.
Oh and I don't have control over the incoming JSON or obviously I would just change the JSON. :-)
Thanks
I think you could do something like along these lines (from looking at the ext docs):
var treePanel = {
xtype: 'treepanel',
loader: new Ext.tree.TreeLoader(),
root: new Ext.tree.TreeNode({
expanded: true,
children: myJsonObject.message.nodes
})
}
The is a 'root' option in the reader for your Store's Proxy that you can use.
proxy: {
reader: {
type : 'json',
root : 'nodes'
},
// Other configs
}