Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法从以下json获取标题_Javascript_Json_Node.js - Fatal编程技术网

Javascript 无法从以下json获取标题

Javascript 无法从以下json获取标题,javascript,json,node.js,Javascript,Json,Node.js,我的应用程序中包含以下代码,该代码以json格式返回一些作业提要: 我的代码如下所示: JobFeed.find().sort('-created').exec(function (err, feeds) { if (err) { return res.status(400).send({ message: errorHandler.getErrorMessage(err) }); } else { _.f

我的应用程序中包含以下代码,该代码以json格式返回一些作业提要:

我的代码如下所示:

JobFeed.find().sort('-created').exec(function (err, feeds) {
    if (err) {
        return res.status(400).send({
            message: errorHandler.getErrorMessage(err)
        });
    } else {

        _.forEach(feeds, function (row, key) {
            console.log(row.data.title); // showing undefined
        });

        res.jsonp(feeds);
    }
});
json如下所示:

  { data:
   { isSaved: null,
     client:
      { lastContractTitle: null,
        feedbackText: '4.78 Stars, based on 13 feedbacks',
        paymentVerificationStatus: 1,
        lastContractPlatform: null,
        totalFeedback: 4.7819242373,
        location: [Object],
        lastContractRid: 0,
        edcUserId: 3728985,
        totalReviews: 13,
        companyRid: 0,
        spentTier: '$7,500+',
        companyName: null },
     amount: { amount: 0, currencyCode: 'USD' },
     createdOn: '2016-10-13T06:30:54+00:00',
     skills: [ [Object], [Object], [Object], [Object] ],
     enterpriseJob: false,
     ciphertext: '~01026b31d972ed826b',
     proposalsTier: null,
     description: 'Hello! We\'re currently searching for a developer with',
     category2: 'Web, Mobile & Software Dev',
     type: 2,
     tierText: 'Intermediate ($$)',
     relevance:
      { hoursInactive: 0,
        id: 208660674,
        publishTime: '1476340265000',
        recommendedEffectiveCandidates: 2,
        effectiveCandidates: 3,
        uniqueImpressions: 0 },
     isApplied: null,
     engagement: '30+ hrs/week',
     recno: 208660674,
     title: 'Server-side and Client-side Game Developer for Indie MMO',
     freelancersToHire: 0,
     maxAmount: { amount: 0, currencyCode: 'USD' },
     duration: 'More than 6 months',
     subcategory2: 'Game Development',
     sticky: false,
     stickyLabel: '',
     feedback: null },
  id: 57ffcdbf717ca50cf0b4cbc1 }
{ data:
   { isSaved: null,
     client:
      { lastContractTitle: null,
        feedbackText: 'No feedback yet',
        paymentVerificationStatus: 1,
        lastContractPlatform: null,
        totalFeedback: 0,
        location: [Object],
        lastContractRid: 0,
        edcUserId: 0,
        totalReviews: 0,
        companyRid: 0,
        spentTier: '$100+',
        companyName: null },
     amount: { amount: 0, currencyCode: 'USD' },
     createdOn: '2016-10-13T06:30:51+00:00',
     skills: [ [Object], [Object], [Object] ],
     enterpriseJob: false,
     ciphertext: '~01c59efb9135ed91d0',
     proposalsTier: null,
     description: 'Hello! We\'re currently searching for a developer with',
     category2: 'Web, Mobile & Software Dev',
     type: 2,
     tierText: 'Entry Level ($)',
     relevance:
      { hoursInactive: 0,
        id: 208660673,
        publishTime: '1476340266000',
        recommendedEffectiveCandidates: 18,
        effectiveCandidates: 74,
        uniqueImpressions: 0 },
     isApplied: null,
     engagement: 'Less than 10 hrs/week',
     recno: 208660673,
     title: 'Wordpress & Stripe developer',
     freelancersToHire: 0,
     maxAmount: { amount: 0, currencyCode: 'USD' },
     duration: 'More than 6 months',
     subcategory2: 'Web Development',
     sticky: false,
     stickyLabel: '',
     feedback: null },
  id: 57ffcdbf717ca50cf0b4cbc2 }
{ data:
   { isSaved: null,
     client:
      { lastContractTitle: null,
        feedbackText: 'No feedback yet',
        paymentVerificationStatus: 5,
        lastContractPlatform: null,
        totalFeedback: 0,
        location: [Object],
        lastContractRid: 0,
        edcUserId: 0,
        totalReviews: 0,
        companyRid: 0,
        spentTier: 'Less than $100',
        companyName: null },
     amount: { amount: 2000, currencyCode: 'USD' },
     createdOn: '2016-10-13T06:30:18+00:00',
     skills: [ [Object], [Object] ],
     enterpriseJob: false,
     ciphertext: '~0101449f91585e8e16',
     proposalsTier: null,
     description: 'I need a Christmas card app before 15th Dec.n',
     category2: 'Web, Mobile & Software Dev',
     type: 1,
     tierText: 'Intermediate ($$)',
     relevance:
      { hoursInactive: 0,
        id: 208660669,
        publishTime: '1476340233000',
        recommendedEffectiveCandidates: 7,
        effectiveCandidates: 52,
        uniqueImpressions: 0 },
     isApplied: null,
     engagement: null,
     recno: 208660669,
     title: 'Christmas Card iPhone App',
     freelancersToHire: 0,
     maxAmount: { amount: 0, currencyCode: 'USD' },
     duration: null,
     subcategory2: 'Mobile Development',
     sticky: false,
     stickyLabel: '',
     feedback: null },
  id: 57ffcdbf717ca50cf0b4cbc3 }
{ data:
   { isSaved: null,
     client:
      { lastContractTitle: null,
        feedbackText: '4.88 Stars, based on 102 feedbacks',
        paymentVerificationStatus: 1,
        lastContractPlatform: null,
        totalFeedback: 4.8843944128,
        location: [Object],
        lastContractRid: 0,
        edcUserId: 0,
        totalReviews: 102,
        companyRid: 0,
        spentTier: '$25,000+',
        companyName: null },
     amount: { amount: 100, currencyCode: 'USD' },
     createdOn: '2016-10-13T06:30:00+00:00',
     skills:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ],
     enterpriseJob: false,
     ciphertext: '~01a04eab3b05372652',
     proposalsTier: null,
     description: 'Hello! We\'re currently searching for a developer with',
     category2: 'Writing',
     type: 1,
     tierText: 'Entry Level ($)',
     relevance:
      { hoursInactive: 0,
        id: 208660668,
        publishTime: '1476340202000',
        recommendedEffectiveCandidates: 2,
        effectiveCandidates: 6,
        uniqueImpressions: 0 },
     isApplied: null,
     engagement: null,
     recno: 208660668,
     title: 'Filipino Blog/Content Writers For a Filipino Site (Using WordPress)',
     freelancersToHire: 3,
     maxAmount: { amount: 0, currencyCode: 'USD' },
     duration: null,
     subcategory2: 'Article & Blog Writing',
     sticky: false,
     stickyLabel: '',
     feedback: null },
  id: 57ffcdbf717ca50cf0b4cbc4 }

我拥有的
foreach
,似乎迭代了每个项目,但我无法获得每个项目的标题。有什么帮助吗?

我不太确定你想做什么,但是如果你的评论中确实有数据,那么这样的方法应该可以奏效:

feeds.forEach(function(feed){
  console.log(feed.data.title);
});

如果想要更快的性能,请使用常规for循环。我在我的项目上测试了这个。如果这不起作用,请告诉我。

这不是JSON。。您可以获取原始JSON数据,如果没有,您可以
fs.writeFileSync('somefile.JSON',JSON.stringify(feed))
@Keith我仍然无法获取每个对象的标题。。。你知道还有其他方法吗?feeds对象就是这个样子吗?它看起来不像一个数组,而是四个独立的对象。运行JSON.stringify(feeds)时会显示什么?它使它看起来像这样:[{“\u id”:“57ffcd9e717ca50cf0b4cb61”,“数据”:{“反馈”:null,“粘贴标签”:“粘贴”:false,“子类别2”:“Web开发”,“持续时间”:“不到1个月”,“最大金额”:{“currencyCode”:“USD”,“amount”:0},“自由职业者ToHire….它是这样工作的,我不知道为什么:var list=JSON.parse(JSON.stringify(feeds));u.forEach(list,function(row,key){console.log(row.data.title);});