来源
<script>
var rcJobsGrid = new revit.grid.TableGrid({ id: 'rcJobsGrid', url: '/jobs/apply/ajax?action=careerCenterBean.jobsGrid.onAJAX&type=METHOD_ACTION', hasPagination: true, hasSearch: true, hasResizeColumns: true, possibleRowsPerPage: [ 10, 20, 30 ], maxRowsVisible: 20, maxColsVisible: 100, rowsPerPage: 20, tabIndex: 0, customRenderers: [{ type: 'STATUS_PROGRESS_BAR_CUSTOM_TYPE', renderer: 'com.adp.wfn.customrenderers.renderStatusProgressBar', toggle: false }], parent: 'rcJobsGrid_parent', onPostRenderTable: 'if(WFN.getWidget("rcJobsGrid_toolbar_delete")!=null){WFN.getWidget("rcJobsGrid_toolbar_delete").set("useBusy",false);}WFN.handleButtonEnabling("rcJobsGrid", "rcJobsGrid_toolbar_delete");', toolbar: [{ id: '_toolbar_add', action: '', active: false, onClick: '', label: '', value: '', title: '', iconClass: '', iconClassDisabled: '', children: null}, { id: '_toolbar_delete', action: '', active: false, onClick: '', label: '', value: '', title: '', iconClass: '', iconClassDisabled: '', children: null}], timeout: 30000, transparent: false, widthType: 'px', store: { identifier: 'id', label: 'name', gridId: 'rcJobsGrid' , customProperties: [{ key: 'USE_DEFAULT_CONFIRM_DELETE_DLG', value: 'false'}, { key: 'OTHER_PAGES_SELECTION_COUNT', value: '0'}, { key: 'TABLE_GRID_DELETE_CONFIRM_MSG', value: 'Are you sure you want to delete the selected records?'}] , url: '/jobs/apply/ajax?action=careerCenterBean.jobsGrid.onAJAX&type=METHOD_ACTION' , lastSort: 0, sortType: 1, total: 6, tabIndex: 0, noDataMessage: 'There are currently no jobs available.' , startPosition: 1, endPosition: 6, gridExpressionString: '#{careerCenterBean.jobsGrid}' , possibleRowsPerPage: '10, 20, 30' , rowsPerPage: 20, maxRowsVisible: 20, maxColsVisible: 100, hasPagination: true, width: 950, widthType: 'px' , transparent: false, hasSearch: true, headerRows: [ { columns: [{ id: '0' , label: 'Job Opening' , align: 'left' , width: 300, widthType: 'px' , locked: false, html: false, hidden: false, sortable: true}, { id: '1' , label: 'Worked In Country' , align: 'left' , width: 200, widthType: 'px' , locked: false, html: false, hidden: false, sortable: true}, { id: '2' , label: 'Location' , align: 'left' , width: 225, widthType: 'px' , locked: false, html: false, hidden: false, sortable: true}, { id: '3' , label: 'Date Posted' , align: 'left' , width: 150, widthType: 'px' , locked: false, html: false, hidden: false, sortable: true}, { id: '4' , label: 'Job ID' , align: 'left' , width: 75, widthType: 'px' , locked: false, html: false, hidden: false, sortable: true}] }], rows: [ { id: '0' , customProperties: [{ key: 'oid', value: '46702'}] , cells: [ { id: '0' , type: 'LINK' , action: '#{careerCenterBean.viewJobPostingDetails}' , align: 'left' , value: 'Research Assistant'}, { id: '1' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'UNITED STATES'}, { id: '2' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'Arlington, VA'}, { id: '3' , type: 'OUTPUT_TEXT' , align: 'left' , value: '04/16/2014'}, { id: '4' , type: 'OUTPUT_TEXT' , align: 'left' , value: '1010'}] , selected: false}, { id: '1' , customProperties: [{ key: 'oid', value: '46747'}] , cells: [ { id: '0' , type: 'LINK' , action: '#{careerCenterBean.viewJobPostingDetails}' , align: 'left' , value: 'Research Analyst'}, { id: '1' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'UNITED STATES'}, { id: '2' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'Arlington, VA'}, { id: '3' , type: 'OUTPUT_TEXT' , align: 'left' , value: '04/16/2014'}, { id: '4' , type: 'OUTPUT_TEXT' , align: 'left' , value: '1011'}] , selected: false}, { id: '2' , customProperties: [{ key: 'oid', value: '46467'}] , cells: [ { id: '0' , type: 'LINK' , action: '#{careerCenterBean.viewJobPostingDetails}' , align: 'left' , value: 'User Experience Researcher'}, { id: '1' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'UNITED STATES'}, { id: '2' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'Arlington, VA'}, { id: '3' , type: 'OUTPUT_TEXT' , align: 'left' , value: '04/08/2014'}, { id: '4' , type: 'OUTPUT_TEXT' , align: 'left' , value: '1007'}] , selected: false}, { id: '3' , customProperties: [{ key: 'oid', value: '15082'}] , cells: [ { id: '0' , type: 'LINK' , action: '#{careerCenterBean.viewJobPostingDetails}' , align: 'left' , value: 'Research Manager'}, { id: '1' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'UNITED STATES'}, { id: '2' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'Arlington, VA'}, { id: '3' , type: 'OUTPUT_TEXT' , align: 'left' , value: '04/03/2014'}, { id: '4' , type: 'OUTPUT_TEXT' , align: 'left' , value: '1004'}] , selected: false}, { id: '4' , customProperties: [{ key: 'oid', value: '46476'}] , cells: [ { id: '0' , type: 'LINK' , action: '#{careerCenterBean.viewJobPostingDetails}' , align: 'left' , value: 'Summer Intern'}, { id: '1' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'UNITED STATES'}, { id: '2' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'Arlington, VA'}, { id: '3' , type: 'OUTPUT_TEXT' , align: 'left' , value: '04/03/2014'}, { id: '4' , type: 'OUTPUT_TEXT' , align: 'left' , value: '1008'}] , selected: false}, { id: '5' , customProperties: [{ key: 'oid', value: '46530'}] , cells: [ { id: '0' , type: 'LINK' , action: '#{careerCenterBean.viewJobPostingDetails}' , align: 'left' , value: 'All Other Jobs'}, { id: '1' , type: 'OUTPUT_TEXT' , align: 'left' , value: 'UNITED STATES'}, { id: '2' , type: 'OUTPUT_TEXT' , align: 'left' }, { id: '3' , type: 'OUTPUT_TEXT' , align: 'left' , value: '04/03/2014'}, { id: '4' , type: 'OUTPUT_TEXT' , align: 'left' , value: '1009'}] , selected: false}] , footerRows: [ ] } });
revit.addOnLoad(_container_, function() {rcJobsGrid.startup();});
</script>
实际上我正在尝试将unicode字符串作为json对象读取,以便我可以迭代它,我无法执行该操作
import json
v= [u'{ id: \'rcJobsGrid\', url: \'/jobs/apply/ajax?action=careerCenterBean.jobsGrid.onAJAX&type=METHOD_ACTION\', hasPagination: true, hasSearch: true, hasResizeColumns: true, possibleRowsPerPage: [ 10, 20, 30 ], maxRowsVisible: 20, maxColsVisible: 100, rowsPerPage: 20, tabIndex: 0, customRenderers: [{ type: \'STATUS_PROGRESS_BAR_CUSTOM_TYPE\', renderer: \'com.adp.wfn.customrenderers.renderStatusProgressBar\', toggle: false }], parent: \'rcJobsGrid_parent\', onPostRenderTable: \'if(WFN.getWidget("rcJobsGrid_toolbar_delete")!=null){WFN.getWidget("rcJobsGrid_toolbar_delete").set("useBusy",false);}WFN.handleButtonEnabling("rcJobsGrid", "rcJobsGrid_toolbar_delete");\', toolbar: [{ id: \'_toolbar_add\', action: \'\', active: false, onClick: \'\', label: \'\', value: \'\', title: \'\', iconClass: \'\', iconClassDisabled: \'\', children: null}, { id: \'_toolbar_delete\', action: \'\', active: false, onClick: \'\', label: \'\', value: \'\', title: \'\', iconClass: \'\', iconClassDisabled: \'\', children: null}], timeout: 30000, transparent: false, widthType: \'px\', store: { identifier: \'id\', label: \'name\', gridId: \'rcJobsGrid\' , customProperties: [{ key: \'USE_DEFAULT_CONFIRM_DELETE_DLG\', value: \'false\'}, { key: \'OTHER_PAGES_SELECTION_COUNT\', value: \'0\'}, { key: \'TABLE_GRID_DELETE_CONFIRM_MSG\', value: \'Are you sure you want to delete the selected records?\'}] , url: \'/jobs/apply/ajax?action=careerCenterBean.jobsGrid.onAJAX&type=METHOD_ACTION\' , lastSort: 0, sortType: 1, total: 6, tabIndex: 0, noDataMessage: \'There are currently no jobs available.\' , startPosition: 1, endPosition: 6, gridExpressionString: \'#{careerCenterBean.jobsGrid}\' , possibleRowsPerPage: \'10, 20, 30\' , rowsPerPage: 20, maxRowsVisible: 20, maxColsVisible: 100, hasPagination: true, width: 950, widthType: \'px\' , transparent: false, hasSearch: true, headerRows: [ { columns: [{ id: \'0\' , label: \'Job Opening\' , align: \'left\' , width: 300, widthType: \'px\' , locked: false, html: false, hidden: false, sortable: true}, { id: \'1\' , label: \'Worked In Country\' , align: \'left\' , width: 200, widthType: \'px\' , locked: false, html: false, hidden: false, sortable: true}, { id: \'2\' , label: \'Location\' , align: \'left\' , width: 225, widthType: \'px\' , locked: false, html: false, hidden: false, sortable: true}, { id: \'3\' , label: \'Date Posted\' , align: \'left\' , width: 150, widthType: \'px\' , locked: false, html: false, hidden: false, sortable: true}, { id: \'4\' , label: \'Job ID\' , align: \'left\' , width: 75, widthType: \'px\' , locked: false, html: false, hidden: false, sortable: true}] }], rows: [ { id: \'0\' , customProperties: [{ key: \'oid\', value: \'46702\'}] , cells: [ { id: \'0\' , type: \'LINK\' , action: \'#{careerCenterBean.viewJobPostingDetails}\' , align: \'left\' , value: \'Research Assistant\'}, { id: \'1\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'UNITED STATES\'}, { id: \'2\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'Arlington, VA\'}, { id: \'3\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'04/16/2014\'}, { id: \'4\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'1010\'}] , selected: false}, { id: \'1\' , customProperties: [{ key: \'oid\', value: \'46747\'}] , cells: [ { id: \'0\' , type: \'LINK\' , action: \'#{careerCenterBean.viewJobPostingDetails}\' , align: \'left\' , value: \'Research Analyst\'}, { id: \'1\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'UNITED STATES\'}, { id: \'2\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'Arlington, VA\'}, { id: \'3\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'04/16/2014\'}, { id: \'4\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'1011\'}] , selected: false}, { id: \'2\' , customProperties: [{ key: \'oid\', value: \'46467\'}] , cells: [ { id: \'0\' , type: \'LINK\' , action: \'#{careerCenterBean.viewJobPostingDetails}\' , align: \'left\' , value: \'User Experience Researcher\'}, { id: \'1\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'UNITED STATES\'}, { id: \'2\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'Arlington, VA\'}, { id: \'3\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'04/08/2014\'}, { id: \'4\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'1007\'}] , selected: false}, { id: \'3\' , customProperties: [{ key: \'oid\', value: \'15082\'}] , cells: [ { id: \'0\' , type: \'LINK\' , action: \'#{careerCenterBean.viewJobPostingDetails}\' , align: \'left\' , value: \'Research Manager\'}, { id: \'1\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'UNITED STATES\'}, { id: \'2\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'Arlington, VA\'}, { id: \'3\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'04/03/2014\'}, { id: \'4\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'1004\'}] , selected: false}, { id: \'4\' , customProperties: [{ key: \'oid\', value: \'46476\'}] , cells: [ { id: \'0\' , type: \'LINK\' , action: \'#{careerCenterBean.viewJobPostingDetails}\' , align: \'left\' , value: \'Summer Intern\'}, { id: \'1\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'UNITED STATES\'}, { id: \'2\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'Arlington, VA\'}, { id: \'3\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'04/03/2014\'}, { id: \'4\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'1008\'}] , selected: false}, { id: \'5\' , customProperties: [{ key: \'oid\', value: \'46530\'}] , cells: [ { id: \'0\' , type: \'LINK\' , action: \'#{careerCenterBean.viewJobPostingDetails}\' , align: \'left\' , value: \'All Other Jobs\'}, { id: \'1\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'UNITED STATES\'}, { id: \'2\' , type: \'OUTPUT_TEXT\' , align: \'left\' }, { id: \'3\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'04/03/2014\'}, { id: \'4\' , type: \'OUTPUT_TEXT\' , align: \'left\' , value: \'1009\'}] , selected: false}] , footerRows: [ ] } }']
print type(v[0])
str_to_load = json.dumps(v[0])
json_data = json.loads(str_to_load)
print json_data
for row in json_data.get('rows',[]):
print row
答案 0 :(得分:0)
这不是有效的JSON;并非所有JavaScript都是JSON。您可以尝试使用以下命令将其转换为JSON:
import re
def repair_json(val):
return re.sub(r'(\w+):', r'"\1":',
val.replace('"', '\u0022').replace("'", '"'))
此:
\uxxxx
unicode转义序列的嵌入式双引号。对于您的给定值,此方法有效:
>>> json.loads(repair_json(v[0]))
{u'maxColsVisible': 100, u'maxRowsVisible': 20, u'hasSearch': True, u'parent': u'rcJobsGrid_parent', u'url': u'/jobs/apply/ajax?action=careerCenterBean.jobsGrid.onAJAX&type=METHOD_ACTION', u'onPostRenderTable': u'if(WFN.getWidget("rcJobsGrid_toolbar_delete")!=null){WFN.getWidget("rcJobsGrid_toolbar_delete").set("useBusy",false);}WFN.handleButtonEnabling("rcJobsGrid", "rcJobsGrid_toolbar_delete");', u'widthType': u'px', u'store': {u'maxRowsVisible': 20, u'endPosition': 6, u'gridId': u'rcJobsGrid', u'gridExpressionString': u'#{careerCenterBean.jobsGrid}', u'noDataMessage': u'There are currently no jobs available.', u'customProperties': [{u'value': u'false', u'key': u'USE_DEFAULT_CONFIRM_DELETE_DLG'}, {u'value': u'0', u'key': u'OTHER_PAGES_SELECTION_COUNT'}, {u'value': u'Are you sure you want to delete the selected records?', u'key': u'TABLE_GRID_DELETE_CONFIRM_MSG'}], u'total': 6, u'hasPagination': True, u'tabIndex': 0, u'headerRows': [{u'columns': [{u'locked': False, u'align': u'left', u'label': u'Job Opening', u'width': 300, u'html': False, u'widthType': u'px', u'sortable': True, u'hidden': False, u'id': u'0'}, {u'locked': False, u'align': u'left', u'label': u'Worked In Country', u'width': 200, u'html': False, u'widthType': u'px', u'sortable': True, u'hidden': False, u'id': u'1'}, {u'locked': False, u'align': u'left', u'label': u'Location', u'width': 225, u'html': False, u'widthType': u'px', u'sortable': True, u'hidden': False, u'id': u'2'}, {u'locked': False, u'align': u'left', u'label': u'Date Posted', u'width': 150, u'html': False, u'widthType': u'px', u'sortable': True, u'hidden': False, u'id': u'3'}, {u'locked': False, u'align': u'left', u'label': u'Job ID', u'width': 75, u'html': False, u'widthType': u'px', u'sortable': True, u'hidden': False, u'id': u'4'}]}], u'rows': [{u'cells': [{u'action': u'#{careerCenterBean.viewJobPostingDetails}', u'align': u'left', u'type': u'LINK', u'id': u'0', u'value': u'Research Assistant'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'1', u'value': u'UNITED STATES'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'2', u'value': u'Arlington, VA'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'3', u'value': u'04/16/2014'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'4', u'value': u'1010'}], u'selected': False, u'id': u'0', u'customProperties': [{u'value': u'46702', u'key': u'oid'}]}, {u'cells': [{u'action': u'#{careerCenterBean.viewJobPostingDetails}', u'align': u'left', u'type': u'LINK', u'id': u'0', u'value': u'Research Analyst'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'1', u'value': u'UNITED STATES'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'2', u'value': u'Arlington, VA'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'3', u'value': u'04/16/2014'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'4', u'value': u'1011'}], u'selected': False, u'id': u'1', u'customProperties': [{u'value': u'46747', u'key': u'oid'}]}, {u'cells': [{u'action': u'#{careerCenterBean.viewJobPostingDetails}', u'align': u'left', u'type': u'LINK', u'id': u'0', u'value': u'User Experience Researcher'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'1', u'value': u'UNITED STATES'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'2', u'value': u'Arlington, VA'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'3', u'value': u'04/08/2014'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'4', u'value': u'1007'}], u'selected': False, u'id': u'2', u'customProperties': [{u'value': u'46467', u'key': u'oid'}]}, {u'cells': [{u'action': u'#{careerCenterBean.viewJobPostingDetails}', u'align': u'left', u'type': u'LINK', u'id': u'0', u'value': u'Research Manager'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'1', u'value': u'UNITED STATES'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'2', u'value': u'Arlington, VA'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'3', u'value': u'04/03/2014'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'4', u'value': u'1004'}], u'selected': False, u'id': u'3', u'customProperties': [{u'value': u'15082', u'key': u'oid'}]}, {u'cells': [{u'action': u'#{careerCenterBean.viewJobPostingDetails}', u'align': u'left', u'type': u'LINK', u'id': u'0', u'value': u'Summer Intern'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'1', u'value': u'UNITED STATES'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'2', u'value': u'Arlington, VA'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'3', u'value': u'04/03/2014'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'4', u'value': u'1008'}], u'selected': False, u'id': u'4', u'customProperties': [{u'value': u'46476', u'key': u'oid'}]}, {u'cells': [{u'action': u'#{careerCenterBean.viewJobPostingDetails}', u'align': u'left', u'type': u'LINK', u'id': u'0', u'value': u'All Other Jobs'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'1', u'value': u'UNITED STATES'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'2'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'3', u'value': u'04/03/2014'}, {u'align': u'left', u'type': u'OUTPUT_TEXT', u'id': u'4', u'value': u'1009'}], u'selected': False, u'id': u'5', u'customProperties': [{u'value': u'46530', u'key': u'oid'}]}], u'maxColsVisible': 100, u'label': u'name', u'width': 950, u'sortType': 1, u'hasSearch': True, u'lastSort': 0, u'widthType': u'px', u'transparent': False, u'url': u'/jobs/apply/ajax?action=careerCenterBean.jobsGrid.onAJAX&type=METHOD_ACTION', u'footerRows': [], u'startPosition': 1, u'identifier': u'id', u'possibleRowsPerPage': u'10, 20, 30', u'rowsPerPage': 20}, u'possibleRowsPerPage': [10, 20, 30], u'hasPagination': True, u'customRenderers': [{u'toggle': False, u'type': u'STATUS_PROGRESS_BAR_CUSTOM_TYPE', u'renderer': u'com.adp.wfn.customrenderers.renderStatusProgressBar'}], u'toolbar': [{u'iconClass': u'', u'title': u'', u'iconClassDisabled': u'', u'children': None, u'value': u'', u'label': u'', u'active': False, u'onClick': u'', u'action': u'', u'id': u'_toolbar_add'}, {u'iconClass': u'', u'title': u'', u'iconClassDisabled': u'', u'children': None, u'value': u'', u'label': u'', u'active': False, u'onClick': u'', u'action': u'', u'id': u'_toolbar_delete'}], u'timeout': 30000, u'hasResizeColumns': True, u'transparent': False, u'id': u'rcJobsGrid', u'rowsPerPage': 20, u'tabIndex': 0}
rows
列表是store
键下的一个键:
for row in data['store']['rows']:
print row
为了探索这些结构,我发现pprint.pprint()
function非常宝贵。