使用外部URL时未定义React - Map函数

时间:2017-07-30 05:41:51

标签: javascript arrays json reactjs axios

我收到通常的错误 .map不是功能。只有在我使用外部api url时才会出现错误,同时当我在浏览器中打开url并将json数据复制到本地文件并通过ajax调用它时它工作得很好。我认为JSON响应中存在错误。我无法理解。

请检查以下代码。当我将 url1 传递给axios时出现错误,当我将 url2 传递给axios时,数据打印得很好。

function ListViewColumnCount(mHandle: THandle): Integer;
begin
   Result := Header_GetItemCount(ListView_GetHeader(mHandle));
end;

function GetListViewText(mHandle: THandle; mStrings: TStrings): Boolean;
var
  vColumnCount: Integer;
  vItemCount: Integer;
  I, J: Integer;
  vBuffer: array[0..255] of Char;
  vPRocessId: DWord;
  vProcess: THandle;
  vPointer: Pointer;
  vNumberOfBytesRead: SIZE_T;
  S: string;
  vItem: TLVItem;
begin
  Result := False;

  if not Assigned(mStrings)
    then
      Exit;

  vColumnCount := ListViewColumnCount(mHandle);
  ShowMessage('There are ' + IntToStr(vColumnCount) + ' columns in this listview');

  if vColumnCount <= 0
    then
      Exit;

  vItemCount := ListView_GetItemCount(mHandle);
  GetWindowThreadProcessId(mHandle, @vProcessId);
  vProcess := OpenProcess(PROCESS_VM_OperaTION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, vProcessId);
  vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
  mStrings.BeginUpdate;

  try
    mStrings.Clear;
    for I := 0 to vItemCount - 1
      do
        begin
          S := '';
          for J := 0 to vColumnCount - 1
            do
              begin
                with vItem do
                  begin
                    mask := LVIF_TEXT;
                    iItem := I;
                    iSubItem := J;
                    cchTextMax := SizeOf(vBuffer);
                    pszText := Pointer(Cardinal(vPointer) + SizeOf(TLVItem));
                  end;
                WriteProcessMemory(vProcess, vPointer, @vItem, SizeOf(TLVItem), vNumberOfBytesRead);
                SendMessage(mHandle, LVM_GETITEM, I, lparam(vPointer));
                ReadProcessMemory(vProcess, Pointer(Cardinal(vPointer) + SizeOf(TLVItem)), @vBuffer[0], SizeOf(vBuffer), vNumberOfBytesRead);
                S := S + #9 + vBuffer;
              end;
          Delete(S, 1, 1);
          mStrings.Add(S);
        end;
  finally
    VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
    CloseHandle(vProcess);
    mStrings.EndUpdate;
  end;

  Result := True;
end;

function retrieveListViewItemsFromAnotherProgram: bool;
begin
  Form1.MyMemo.Clear;
  GetListViewText(123456, Form1.MyMemo.Lines); //where 123456 is the handle of the ListView of the other program found using Microsoft Spy++
  Result := true;
end;

这是link工作演示

1 个答案:

答案 0 :(得分:1)

收到json响应后,我使用JSON.parse解析它,然后错误被清除。

connect()